WCF over Http and Https resolving local address in WSDL - c#

Recently we added HTTPS to one of our WCF services that is exposed over REST and SOAP endpoints.
When we made this modification, the SOAP endpoints are experiencing issues that I am unable to find fixes for.
The problem I am having right now is that when the HTTP endpoint is consumed, the SOAP address given in the WSDL is pointing to the local address. This is not allowing the service to be consumed over HTTP and only of HTTPS.
The web.config is the following for the relevant section:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpsBinding">
<security mode="Transport"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="MyServiceBehavior"
name="Some.Path.To.MyService">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="basicHttpsBinding"
contract="Some.Path.To.IMyService"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PingPostServiceBehavior">
<serviceThrottling maxConcurrentInstances="800"
maxConcurrentCalls="800"
maxConcurrentSessions="800"/>
<!--<useRequestHeadersForMetadataAddress/>-->
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above 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>
When I go to the PRODUCTION HTTP WSDL address, the local address is given in the soap address element as shown in following image. I apologize about the bad censor job.

Related

Problem with configuring HTTPS on my WCF service

I am trying to add transport security layer to my WCF service. But after following all the instructions i still get error "Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http]."
Already did all needed configurations in IIS Manager and add need code in web.config but i still have a feeling i am missing something
web.config:
<system.serviceModel>
<services>
<service name="MyNameSpace.MyService" behaviorConfiguration="secureBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="secureHttpBinding" contract="MyNameSpace.IMyService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="secureBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
There is no problem with your present configuration, configure an https endpoint and it uses Transport security mode. One more thing we need to do is configuring an https binding address in IIS binding module. Like below.
It locates in the IIS site binding module.
Then we could use the above https service address to access it.
https://IP:4431/Service1.svc (service base address)
Feel free to let me know if the problem still exists.

Problems with Hosting WCF service on IIS (Using WAS) for netTCP bindings?

I created a simple WCF service and hosted it in IIS by creating a new website. In Web.config file,I am providing bindings for http and net tcp.
I created a console client and adding service reference. It generates two binding in client config - for http and for tcp. When I try to invoke the service using tcp, I get this error -
An unhandled exception of type 'System.ServiceModel.EndpointNotFoundException' occurred in mscorlib.dll
Additional information: There was no endpoint listening at net.tcp://computername/Service.svc that could accept the message. This is often caused by an incorrect address or SOAP action.
when I run using Http endpoint , it works fine.
Note -
I am using Windows 10 OS, IIS 10.0 and WPAS\WAS (Windows Process Activation Service) are installed. I already enabled\checked HTTP Activation, TCP Activation in .Net framework in Windows features. And modified IIS server settings to include net tcp. Please check it in attached image.
My website Web.config file looks like
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NewBinding0" portSharingEnabled="true">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="My" name="WCFServiceOM.Service1"> <!-- the service name must match the configuration name for the service implementation. -->
<endpoint address="" binding="basicHttpBinding" contract="WCFServiceOM.IService1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint binding="netTcpBinding" bindingConfiguration="NewBinding0" contract="WCFServiceOM.IService1" />
<endpoint address="mexOM" binding="mexTcpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8087/Service1" />
<add baseAddress="http://localhost:7777/Service1"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehanior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="My">
<!-- 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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
And my client App.Config look like
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IService1">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="http://computername:7777/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
<endpoint address="net.tcp://computername/Service.svc" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService1" contract="ServiceReference1.IService1"
name="NetTcpBinding_IService1" />
</client>
</system.serviceModel>

WCF call returning 404

So I have a WCF service that calls another WCF service. I'm trying to debug the first service, so I attempted to run it. It fails with a
There was no endpoint listening at http://<host>/ConfigurationService/ConfigurationService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The inner exception is
{"The remote server returned an error: (404) Not Found."}
Reference:
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IConfigurationService/GetGlobalConfigurationGroup", ReplyAction="http://tempuri.org/IConfigurationService/GetGlobalConfigurationGroupResponse")]
ConfigurationGroup GetGlobalConfigurationGroup();
Taking that exact endpoint and putting it in a browser works. Taking it and putting it in WCFTestClient works. This code is already running in production, so I don't know what I'm doing wrong. I debug into the call and I see it's being sent as a POST instead of a GET. I'm assuming that's the culprit, but I have no idea on how to fix it or why it's magically different. I've looked at WCF method sending POST instead of GET and the link in that answer, but I don't understand it, couldn't get it to work, and the class that extends it is a generated class and won't debug into it either.
I put on failure request logging on the Configuration service, which logs something if I go to a bad location (ConfigurationService.svc1) but not when calling this.
<system.serviceModel>
<client>
<endpoint address="http://<host>/SecurityService/SecurityService.svc"
behaviorConfiguration="defaultBehavior" binding="basicHttpBinding"
bindingConfiguration="defaultHttpBinding" contract="Service.ISecurityService"
name="SecurityService" />
<endpoint address="http://<host>/ConfigurationService/ConfigurationService.svc"
behaviorConfiguration="defaultBehavior" binding="basicHttpBinding"
bindingConfiguration="defaultHttpBinding" contract="Service.IConfigurationService"
name="ConfigurationService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="defaultHttpBinding" closeTimeout="00:10:00" openTimeout="00:10:00"
receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="defaultBehavior">
<dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
<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="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Config for Configuration Service:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<services>
<service name="ConfigurationService" behaviorConfiguration="defaultBehavior">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="defaultHttpBinding"
contract="IConfigurationService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="defaultHttpBinding" maxReceivedMessageSize="2147483647" openTimeout="00:10:00" closeTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="20971520"/>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="defaultBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Edit: I've noticed that it only exhibits this behavior when running a web project.
Try using Data Contracts in the service that you are trying to call.
https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx
Here a brief explanation about what they are and how they works.
I think that this is the error because of your error 'OperationContractAttribute'
Maybe is only the ServiceContract.
I hope this helps
In a multi-process environment where services are distributed and applications using those services are communicating via WCF, service contracts must be serialize-able. The easiest way to ensure serialization of contract objects is to decorate them with data contracts attributes as described here: https://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx
Without proper serialization your services will still work under some conditions and unless you're attached to all your relevant processes while debugging you won't see any error thrown. Even logging will sometimes fail to show anything (or at least anything useful).
This likely isn't a configuration problem since you're using dataContractSerializer. Decorate your service contract classes so they can be serialized over WCF.
I once had this problem. Turns out I had the wrong address for the service in the configuration of my web project.

Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http]

My WebConfig:
<bindings>
<webHttpBinding>
<binding name="SecureBasicRest">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="svcBehavior">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="svcEndpoint">
<webHttp helpEnabled="true"/>
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="SvcContract.Authenticate" behaviorConfiguration="svcBehavior">
<endpoint binding="webHttpBinding" bindingConfiguration="SecureBasicRest"
behaviorConfiguration="svcEndpoint" name="webHttp"
contract="SvcContract.Authenticate" />
</service>
</services>
I have to make this work with
https://localhost:6188/Authenticate/Login?username=user&password=pass&ip=127.0.0.1
Change
<serviceMetadata httpsGetEnabled="true"/>
to
<serviceMetadata httpsGetEnabled="false"/>
You're telling WCF to use https for the metadata endpoint and I see that your'e exposing your service on http, and then you get the error in the title.
You also have to set <security mode="None" /> if you want to use HTTP as your URL suggests.
You would need to enable https binding on server side. IISExpress in this case. Select Properties on website project in solution explorer (not double click). In the properties pane then you need to enable SSL.
I solved the issue by adding https binding in my IIS websites and adding 443 SSL port and selecting a self signed certificate in binding.
To make it work you have to replace a run this line of code
serviceMetadata httpGetEnabled="true"/> http instead of https
and security mode="None" />
In the endpoint tag you need to include the property address=""
<endpoint address="" binding="webHttpBinding" bindingConfiguration="SecureBasicRest" behaviorConfiguration="svcEndpoint" name="webHttp" contract="SvcContract.Authenticate" />
In our case; I had to remove the "<baseAddressPrefixFilters" from the config file.

How to configure webHttp Binding while creating a WCF service in Azure?

I am developing a WCF WebRole service in Azure and need to invoke a method that to give employee data in JSON format.But unlike a normal WCF Web Service, I dont know how to configure the "Web.config" for WCF Webrole and my code "Web.config" for normal WCF service is below:
<system.serviceModel>
<services>
<service name="empl.Service1" behaviorConfiguration="empl.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="" binding="webHttpBinding" contract="empl.IService1" behaviorConfiguration="web">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="empl.Service1Behavior">
<!-- 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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
And my code "Web.config"for WCF WebRole (Azure)is as follow
<system.serviceModel>
<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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /></system.serviceModel>
Now I need to get the URI access "http://localhost/Service1.svc/GetId" where it should respond in JSON data. But for me it is showing that "HTTP400 Bad Request". Help me out.
The bad request might be that the request being sent is not valid. If your service was not accessible or found it would have been a different Http error code. Try enabling tracing on your service to see the cause for bad request. To enable tracing follow this link

Categories

Resources