WCF can't connect to an ASMX Web Service - wcf

I'm using WCF to connect to a remote web service (asmx) for testing at this point. The remote web service is unsecured for now (no https, no user name, password). I can add the WCF service reference, and all the classes are generated ok. When I make the call to the webservice, it just hangs.
So I can connect with the SOAP UI tool and return data just fine. I'm thinking it is something wrong with my binding. Anyone see anything I'm missing?
<system.serviceModel>
<bindings>
<!-- Need to change some settings here for HTTPS and Basic Auth when those go online-->
<basicHttpBinding>
<binding name="ServiceSoap" 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://<snip>/Service.asmx"
binding="basicHttpBinding" bindingConfiguration="ServiceSoap"
contract="PRIOrderService.ServiceSoap" name="ServiceSoap" />
</client>
</system.serviceModel>

Requesting the wsdl endpoint does not trigger a creation of the instance of your service. If you are using a custom service host factory look at that, otherwise look at the constructor of your service implementation or debug the service method itself.

Related

WCF service binding content type mismatch - text/xml and application/soap+xml

I have been at this for a few days trying to figure out why I am getting a content type mismatch error in my binding. There are countless other people that seem to be having this issue but all the resolutions don't apply or haven't worked.
I have looked everywhere trying to figure out why I am getting the following error:
Server Error in '/' Application.
The content type application/soap+xml; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 823 bytes of the response were:
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><GetQuoteResponse xmlns="http://soap.service.GMO.com"><Quote_Response><errorMessage></errorMessage><return_List><item><errorMessage></errorMessage><monthlyPremiumAmount>6.0</monthlyPremiumAmount><webID>7P3W4Txst</webID><basePer1>1000.0</basePer1><basePer2>0.0</basePer2><baseRate1>0.05</baseRate1><baseRate2>0.0</baseRate2><benefitID>5365</benefitID><coverageAmount>100000</coverageAmount><grossPer1>1000.0</grossPer1><grossPer2>0.0</grossPer2><grossRate1>0.06</grossRate1><grossRate2>0.0</grossRate2></item></return_List></Quote_Response></GetQuoteResponse></soapenv:Body></soapenv:Envelope>.
The web service I am consuming is not hosted in IIS. The web service itself seems to be working properly because we use SoapUI and get all the proper results returned to us. As you can also see from the above error message, values are being returned from the web service.
I have also been using Fiddler and am able to confirm that the request header content type is text/xml and the response header content type is application/soap+xml.
We have a datalayer where the service reference resides. The app.config looks like this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="IMSQuoteServiceBinding" 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://hostingServerName:81/cgi-bin/jsmdirect?IMSQuote"
binding="basicHttpBinding" bindingConfiguration="IMSQuoteServiceBinding"
contract="Quote.IMSQuoteServicePortType" name="IMSQuoteServicePort" />
</client>
</system.serviceModel>
The web site web.config looks like this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="IMSQuoteServiceBinding" 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://hostingServerName:81/cgi-bin/jsmdirect?IMSQuote"
binding="basicHttpBinding" bindingConfiguration="IMSQuoteServiceBinding"
contract="Quote.IMSQuoteServicePortType" name="IMSQuoteServicePort" />
</client>
Any help would be very much appreciated. I am somewhat new to WCF and am open to any and all ideas.
Thank you all in advance for your help. If you need me to provide any more information, please let me know.
Just as an update.
I changed the service binding from basicHttpBinding to wsHttpBinding. Changing the binding to wsHttpBinding changed the SOAP service to send as a SOAP 1.2 call rather than a SOAP 1.1 call. Once I did this, the content types matched on the send and receive calls which resolved the binding mismatch error.

WCF Binding Transport/Windows Binding Security Not Being Enforced

I'm in the process of adding SSL security with Windows authentication to a formerly unsecured IIS hosted WCF service application. To my surprise, I found that two of the service endpoints were already using a Binding with Transport and Windows security. This is confusing because the client applications consuming this service are not configured to use Transport security or Windows credentials. Here is the service config:
<binding name="LargeBuffer" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
...
<service behaviorConfiguration="WebServices.GCServiceBehavior"
name="WebServices.GCService">
<endpoint address="" binding="basicHttpBinding" name="GCSecuredEndpoint"
bindingName="largeBuffer" contract="WebServices.IGCService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
When I use Visual Studio to generate the client proxy and configuration, it creates this:
<binding name="GCSecuredEndpoint" 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>
...
<endpoint address="http://devservices.mysite.com/GCService/GCService.svc"
binding="basicHttpBinding" bindingConfiguration="GCSecuredEndpoint"
contract="GCSvc.IGCService" name="GCSecuredEndpoint" />
Notice it's security mode="None" and Transport ClientCredentialType is None instead of Windows. When I call a method on the GCService it succeeds. I would expect it to first complain that I'm trying to access over http instead of https, but it doesn't. Next I would expect it to not authenticate or complain that the client endpoint doesn't match the service in terms of authentication, but it doesn't.
I have another service in the same application that I had just setup with Transport/Windows security just without all the buffer/readquota stuff. For starters, when I generate the client proxy/config in VS for this service, it automatically uses the https address, transport security, and windows authentication. If I manually change it to use None for both, as above, a call to one of the service methods does not succeed, as expected. Why is the GCService above working?
The server config has
bindingName="largeBuffer"
instead of
bindingConfiguration="LargeBuffer"
The LargeBuffer binding configuration was never being used.

Calling SOAP UI mock service with WCF: "The provided URI scheme 'https' is invalid; expected 'http'."

A colleague of mine gave me a copy of a mock service project for SOAP UI. I can open and run this mock service fine on my machine.
It is running at address: http://localhost:8088/mockShipmentInformationService
The WSDL is provided on address: http://localhost:8088/mockShipmentInformationService_SOAPBinding?WSDL
Using the WSDL provided, I added a Service Reference to the application project. In order to test the methods calling the service, I also added the service reference to the Unit testing project.
For both projects, the following is added to the app.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ShipmentInformationService_SOAPBinding" 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://localhost:8088/mockShipmentInformationService_SOAPBinding"
binding="basicHttpBinding" bindingConfiguration="ShipmentInformationService_SOAPBinding"
contract="ShipmentInformationService.ShipmentInformationService"
name="ShipmentInformationServicePort" />
</client>
</system.serviceModel>
As you can see, the URL is using the normal http protocol, not https. Also, my security mode is set to "none". Yet, I keep on getting the following error message, when attempting to call the service method:
The provided URI scheme 'https' is invalid; expected 'http'.
Parameter name: via
What gives? Might there be some URLs defined somewhere that are wreaking havoc? Where should I look?
I just discovered that it was all in the app.config files. The application project had a wrong URL in the applicationSettings section and the URL wasn't present there for the unit testing project. I can now at least call the service, although I am having some other issues now.

WCF + net.tcp Communication Timeout problem

I have some critical problem in my project. During transaction time with (wcf + netTCP)
I was getting the exception is.
The communication object,
System.ServiceModel.Channels.ClientFramingDuplexSessionChannel,
cannot be used for communication because it is in the Faulted state.
In WCF service app.config add binding tag with timeout specification. But my transaction has been ended within 10 min. what was the problem..
<bindings>
<basicHttpBinding>
<binding name="ServiceSoap" closeTimeout="0:01:00" openTimeout="0:01:00" receiveTimeout="10:00:00" sendTimeout="10:00: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>
<netTcpBinding>
<binding name="b1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="infinite" sendTimeout="10:00:00"
transferMode="Buffered"
maxBufferPoolSize="524288"
maxBufferSize="65536"
maxConnections="10"
maxReceivedMessageSize="65536">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
Any one help me !!!..
I'm not sure why you think its a timeout issue? The error message doesn't suggest a timeout has ocured. Could the server be throwing an exception?
I would strongly recommend setting up WCF tracing. Its a bit involved but really worth doing as I've solved many obscure WCF issue with it.
This is not a complete answer but if you are using the client + server on the same machine you can use a named-pipe binding instead of netTcp
The binding section the configurations might look like this.
<netNamedPipeBinding>
<binding name="infiniteOpenBindingConfig" receiveTimeout="infinite" closeTimeout="infinite">
</binding>
</netNamedPipeBinding>
To keep the binding alive indefinitely the configuration above must be set both on server and client.
Try adding this to your netTcpBinding:
<reliableSession inactivityTimeout="infinite" enabled="true" />
And if that doesn't work, enable WCF tracing to find out what's killing it.

Client calls .asmx, Server exposes WCF endpoint

We have a client that has been configured to connect to an asmx service. We don't want to ask our customers to update their configuration, but we would like to upgrade our service to use WCF. Does anyone know if WCF supports this? If so, what would the configuration file look like?
Our asmx service looks like this:
<bindings>
<binding name="ATransactionSoap" 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://.../atransaction.asmx" binding="basicHttpBinding" bindingConfiguration="ATransactionSoap" contract="ATransactionSoap" name="ATransactionSoap" />
In response to your follow-up question:
any way to use WCF without changing the URL of the service?
Yes, you can make the old .asmx url re-direct to your .svc url. It requires configuration changes on the service side as well as a change to your .asmx file. But your existing client can continue to connect unchanged in any way. See http://kaushikrabadiya.blogspot.com/2008/11/how-to-use-asmx-extension-to-handle-wcf.html.
Your client won't have to change, except to change the URL of the service.