I have a WCF project with CSLA and I have published this service and MVC application in my IIS Server, but it's throwing one error when calling the service from Web app
System.ServiceModel.Security.SecurityNegotiationException: The caller was not authenticated by the service. ---> System.ServiceModel.FaultException: The request for security token could not be satisfied because authentication failed.
This is my service web.config
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="Csla.Server.Hosts.WcfPortal" behaviorConfiguration="returnFaults">
<endpoint binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IWcfPortal" contract="Csla.Server.Hosts.IWcfPortal" />
</service>
<service name="Csla.Server.Hosts.Mobile.WcfPortal" behaviorConfiguration="returnFaults">
<endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpBinding_IWcfPortal" contract="Csla.Server.Hosts.Mobile.IWcfPortal" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding_IWcfPortal" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647">
<readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647" maxDepth="2147483647" />
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="wsHttpBinding_IWcfPortal" maxReceivedMessageSize="2147483647">
<readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647" maxDepth="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="returnFaults">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I have consume this service in my MVC web.config like this.
<add key="CslaAuthentication" value="Csla" />
<add key="CslaDataPortalProxy" value="Csla.DataPortalClient.WcfProxy, Csla" />
<add key="CslaDataPortalUrl" value="http://www.someurl.net/WcfFullPortal.svc" />
Then after I have called service directly from my service project, that was working fine.
<add key="CslaDataPortalUrl" value="http://localhost:11170/WcfFullPortal.svc" />
And also tried with published IP address, that also working fine
<add key="CslaDataPortalUrl" value="http://10.4.56.75/WcfFullPortal.svc" />
Only problem when I use published host name(http://www.someurl.net/WcfFullPortal.svc). And I have open this URL in by browser that was working.
Add following binding configuration right after the section in the web.config <system.serviceModel> section.
<bindings>
<wsHttpBinding>
<binding name="TheBindingConfig">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
just Change Csla.DataPortalClient.WcfProxy to Csla.DataPortalClient.HttpProxy
and <add key="CslaDataPortalUrl" value="http://www.someurl.net/WcfFullPortal.svc" /> to <add key="CslaDataPortalUrl" value="http://www.someurl.net/DataPortal/PostAsync" />
And also add
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
HttpContext.Current.User = new Csla.Security.UnauthenticatedPrincipal();
}
in Global.asax.cs
Related
I am working on a project where one team created wcf service and we MVC team has to consume that service and passing parameters to that service. On going with different ways of calling the service we are unable to call that service because of the following errors:
No connection could be made because the target machine actively refused it 127.0.0.1:1295
No endpoint configured
Endpoint is not listening
Could not find endpoint "" and contract in service model client configuration.
Remote server returning 500 (Internal error)
Please help
[ServiceContract]
public interface ITnTService
{
[OperationContract]
List<GetCity_Result> Getcity();
[OperationContract]
bool PContact(Person item);
}
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="TnT.Services.TnTService">
<endpoint address="basic1" binding="basicHttpBinding" contract="TnT.Services.ITnTService"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
<connectionStrings>
<add name="TnTEntities" connectionString="metadata=res://*/TnT_Model.csdl|res://*/TnT_Model.ssdl|res://*/TnT_Model.msl;provider=System.Data.SqlClient;provider connection string="data source=183.82.48.194;initial catalog=TnT;persist security info=True;user id=dev;password=dev;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
There is no baseaddress in you config file:
<services>
<service name="TnT.Services.TnTService">
<endpoint address="basic1" binding="basicHttpBinding" contract="TnT.Services.ITnTService"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:1295"/>
</baseAddresses>
</host>
</service>
</services>
I've got an WCF .svc file added to my MVC3 project and I'm trying to prevent the service being accessed over HTTP.
With the config below my service is available over https on one port and then over http on another.
How can I prevent this?
Thanks
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="TS">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Endpoints" behaviorConfiguration="Default">
<endpoint address="https://localhost:44301/Services/Endpoints.svc" binding="basicHttpBinding" bindingConfiguration="TS" contract="UkerLtd.Services.IEndpoints"></endpoint>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="false" httpsGetUrl="https://localhost:44301/Services/Endpoints.svc" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
</system.serviceModel>
You can comment or remove the second endpoint for the IMetadataExchange,
since it is for the same service, the metadata will be exposed by the
httpsGetEnabled="true" in the serviceBehaviors/serviceMetadata.
Otherwise you could "Set up IIS to require SSL", but since it's not an option..
hope this helps.
When I update a Service Reference I end up with :
An endpoint configuration section for contract 'MyService.MainServiceSoap' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.
my web.config ends up like this:
endpoints:
<endpoint address="http://localhost/main/MainService.asmx"
binding="basicHttpBinding" bindingConfiguration="MainServiceSoap"
contract="MyService.MainServiceSoap" name="MainServiceSoap" />
<endpoint address="http://localhost/main/MainService.asmx"
binding="customBinding" bindingConfiguration="MainServiceSoap12"
contract="MyService.MainServiceSoap" name="MainServiceSoap12" />
bindings:
<basicHttpBinding>
<binding name="MainServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="655360" maxBufferPoolSize="5242880" maxReceivedMessageSize="655360"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="81920" maxArrayLength="163840"
maxBytesPerRead="40960" maxNameTableCharCount="163840" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="MainServiceSoap12">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
</customBinding>
I manually delete customBinding and Soap12 endpoint and everything works fine. But if I update the service again (right click Update Service Reference) the added custom binding is added again causing error and the need to manually remove from config file.
Does someone knows how to fix this ? I don't want/need a custom soap12 binding.
This is the service config file:
<?xml version="1.0"?>
<configuration>
<system.web>
<globalization culture="es-PY" uiCulture="es-PY"/>
<customErrors mode="Off"/>
<webServices>
<!-- Tried adding and/or removing protocols and conformanceWarnings -->
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
<!-- -->
<conformanceWarnings>
<remove name="BasicProfile1_1"/>
</conformanceWarnings>
</webServices>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="standard" maxReceivedMessageSize="6553600" maxBufferSize="6553600" transferMode="Streamed" helpEnabled="true" automaticFormatSelectionEnabled="true">
<readerQuotas maxStringContentLength="65536000" maxArrayLength="163840" />
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<!--<serviceMetadata httpGetEnabled="true"/>-->
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<!-- Tried setting multipleSiteBindingEnalbed true and false -->
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
<!-- -->
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<connectionStrings>
<clear/>
<add name="GamblingEntities" connectionString="..." providerName="System.Data.EntityClient" />
<add name="GamblingSiteEntities" connectionString="..." providerName="System.Data.EntityClient" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<clear/>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,
Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</DbProviderFactories>
</system.data>
</configuration>
The new ASMX runtime in .NET 2.0 supports SOAP 1.2. At this moment SOAP 1.1 is most widely being used in the industry. In the .NET Framework both SOAP 1.1 and SOAP 1.2 are supported. This means that the Web Services created in .NET Framework 2.0 will be configured to support both SOAP 1.1 and SOAP 1.2 messages. This indirectly means that the WSDLs thus created for the Web Service will have two types of bindings, i.e., SOAP 1.1 and SOAP 1.2.
Taken from here
This is why two bindings are being generated.
<remove name="HttpSoap12"/>
I guess this i how you disable this now i can understand why you see this as a workaround.
Something may have caused this when you moved your web service to the new framework and this is why some of your older web services on 1.1 possibly don't respond in the same way.
Try targeting 2.0 framework maybe to see what happens.
There is no solid workaround. I voted up your question. I am a victim of same problem, Although now I switched to generating dll using svcutil but this issue has been reported to Microsoft here update-or-configure-an-existing-service-reference-in-sl-application-you-get-duplicate-binding-and-endpoint-information
They said, it's fixed in VS2010 but I confirm it's not, I have VS2010 SP1 installed too but this is not fixed in SP1 also. So there this no fix given and bug is closed as 'External'. strange.
On the bug report page, you can also find a workaround but I find that messy.
Another workaround is creating service client object with binding name hard-coded to avoid double endpoint
MyService.MainServiceSoap mainServiceSoap = new MyService.MainServiceSoap("MainServiceSoap");
or at last we can open another bug report at Microsoft and vote up to fix it.
I just call svcutil.exe manually to rebuild my proxy class. Much simpler.
I am trying to test an MVC application that uses WCF web service. It works fine when I run it using the dev server in VS2010. However when I deploy it on IIS7 and try to invoke any service method in my controller code I get the following error:
(405) Method Not Allowed
Does anyone know how to resolve this issue?
My web config entries as follows:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAuthenticationService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://SiteName/ServiceName/AuthenticationService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAuthenticationService"
contract="AuthService.IAuthenticationService" name="BasicHttpBinding_IAuthenticationService">
</endpoint>
</client>
</system.serviceModel>
sounds like the old "ASP.NET is not installed or register to your IIS" problemo Try registering it using
aspnet_regiis –i –enable
from a command prompt run under admin rights.
Duh...the WCF service and the MVC app had mismatched .NET versions! :( silly me.
I have two ASP.Net MVC applications, let's say Site1 and Site2.
For now, I can successfully access Site1 by visiting http://localhost/
Here's my IIS Express applicationhost.config file:
<sites>
<site name="Site1" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="%IIS_USER_HOME%\wwwroot\Site1" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":80:localhost" />
<binding protocol="http" bindingInformation=":80:10.49.0.137" />
</bindings>
</site>
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\logs\tracelogfiles" enabled="false" maxLogFileSizeKB="1024" />
</siteDefaults>
<applicationDefaults applicationPool="IISExpressAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
What I want now is:
Access Site1 on http://localhost/Site1
Place Site2 on %IIS_USER_HOME%\wwwroot\Site2
Access Site2 on http.//localhost/Site2
How should I change the above applicationhost.config to achieve what I want?
Thanks.
change your applicationhost.config as shown below and restart IIS Express.
<sites>
<site name="Site1" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="%IIS_USER_HOME%\wwwroot\" />
</application>
<application path="/site1">
<virtualDirectory path="/" physicalPath="%IIS_USER_HOME%\wwwroot\Site1" />
</application>
<application path="/site2">
<virtualDirectory path="/" physicalPath="%IIS_USER_HOME%\wwwroot\Site2" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":80:localhost" />
<binding protocol="http" bindingInformation=":80:10.49.0.137" />
</bindings>
</site>
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\logs\tracelogfiles" enabled="false" maxLogFileSizeKB="1024" />
</siteDefaults>
<applicationDefaults applicationPool="IISExpressAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
Check this great entry.
Working with SSL at Development Time is easier with IISExpress - Scott Hanselman
Execute netsh command after applicationHost.config append binding.
netsh http add urlacl url=http://10.49.0.137:80/ user=everyone