WCF to communicate with DPWS device and IIS hosted application

Hello Everbody,

I have to connect .Net Micro Framework application (on FEZ Cobra) to an existing web service hosted in WCF on a Windows Service / IIS.

So I have tested the HelloWorldServer_WCF and HelloWorldClient_MF source in the .net micro framework 4.1 to understand how works the DPWS and realize WCF communication.

The samples work well but when I have tried to connect HelloWorldClient_MF application to my own hosted WCF HelloWorldServer_WCF application on IIS, I have got the following error from the ServiceHelloWCFClientProxy.cs source section Send service request

public virtual HelloWCFResponse HelloWCF(HelloWCF req)
 {
 // Create request header
 String action;
 action = "http://localhost/ServiceHelloWCF/IServiceHelloWCF/HelloWCF";
 WsWsaHeader header;
 header = new WsWsaHeader(action, null, EndpointAddress, m_version.AnonymousUri, null, null);
 WsMessage request = new WsMessage(header, req, WsPrefix.None);
 // Create request serializer
 HelloWCFDataContractSerializer reqDcs;
 reqDcs = new HelloWCFDataContractSerializer("HelloWCF", "http://localhost/ServiceHelloWCF");
 request.Serializer = reqDcs;
 request.Method = "HelloWCF";
 // Send service request
 m_requestChannel.Open();
 WsMessage response = m_requestChannel.Request(request); // Get the System.IO.IOException
 m_requestChannel.Close();
 // Process response
 HelloWCFResponseDataContractSerializer respDcs;
 respDcs = new HelloWCFResponseDataContractSerializer("HelloWCFResponse", "http://localhost/ServiceHelloWCF");
 HelloWCFResponse resp;
 resp = ((HelloWCFResponse)(respDcs.ReadObject(response.Reader)));
 return resp;
 }
#### Exception System.IO.IOException - 0x00000000 (3) ####
 #### Message: 
 #### Ws.Services.Binding.HttpTransportBindingElement::OnProcessInputMessage [IP: 0059] ####
 #### Ws.Services.Binding.BindingElement::ProcessInputMessage [IP: 0019] ####
 #### Ws.Services.Binding.BindingElement::ProcessInputMessage [IP: 000f] ####
 #### Ws.Services.Binding.RequestChannel::ReceiveMessage [IP: 002c] ####
 #### Ws.Services.Binding.RequestChannel::Request [IP: 0017] ####
 #### localhost.ServiceHelloWCF.ServiceHelloWCFClientProxy::HelloWCF [IP: 0047] ####
 #### Microsoft.SPOT.Sample.TestApplication::Run [IP: 005a] ####
Une exception de première chance de type 'System.IO.IOException' s'est produite dans MFWsStack.dll
Une exception non gérée du type 'System.IO.IOException' s'est produite dans MFWsStack.dll

After spending time on it, I have noticed that the WSDL from the sample is bit different from the WSDL generate with MfSvcUtil tool. See the Bold lines on the post bottom .

Is there some doc from Microsoft providing guidance on how use WCF to communicate with DPWS devices?

Any ideas would be appreciated.
Thx in advace for your help.

Cedric

WSDL from HelloWorldServer_WCF Sample:

 <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://localhost/ServiceHelloWCF" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:i0="http://tempuri.org/"xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" name="ServiceHelloWCF"targetNamespace="http://localhost/ServiceHelloWCF">
 <wsdl:import namespace="http://tempuri.org/" location="http://172.30.5.135:8084/319D0A4D-2253-47DC-AC4A-C1951FF6667D?wsdl=wsdl0"/>
 <wsdl:types>
 <xsd:schema targetNamespace="http://localhost/ServiceHelloWCF/Imports">
 <xsd:import schemaLocation="http://172.30.5.135:8084/319D0A4D-2253-47DC-AC4A-C1951FF6667D?xsd=xsd0" namespace="http://localhost/ServiceHelloWCF"/>
 <xsd:import schemaLocation="http://172.30.5.135:8084/319D0A4D-2253-47DC-AC4A-C1951FF6667D?xsd=xsd1"namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
 </xsd:schema>
 </wsdl:types>
 <wsdl:message name="IServiceHelloWCF_HelloWCF_InputMessage">
 <wsdl:part name="parameters" element="tns:HelloWCF"/>
 </wsdl:message>
 <wsdl:message name="IServiceHelloWCF_HelloWCF_OutputMessage">
 <wsdl:part name="parameters" element="tns:HelloWCFResponse"/>
 </wsdl:message>
 <wsdl:portType name="IServiceHelloWCF">
 <wsdl:operation name="HelloWCF">
 <wsdl:input wsaw:Action="http://localhost/ServiceHelloWCF/IServiceHelloWCF/HelloWCF" message="tns:IServiceHelloWCF_HelloWCF_InputMessage"/>
 <wsdl:output wsaw:Action="http://localhost/ServiceHelloWCF/IServiceHelloWCF/HelloWCFResponse" message="tns:IServiceHelloWCF_HelloWCF_OutputMessage"/>
 </wsdl:operation>
 </wsdl:portType>
 <wsdl:service name="ServiceHelloWCF">
 <wsdl:port name="WSHttpBinding_IServiceHelloWCF" binding="i0:WSHttpBinding_IServiceHelloWCF">
 <soap12:address location="http://172.30.5.135:8084/319D0A4D-2253-47DC-AC4A-C1951FF6667D"/>
 <wsa10:EndpointReference>
 <wsa10:Address>
 http://172.30.5.135:8084/319D0A4D-2253-47DC-AC4A-C1951FF6667D
 </wsa10:Address>
 </wsa10:EndpointReference>
 </wsdl:port>
 </wsdl:service>
 </wsdl:definitions>

WSDL from my own HelloWorldServer_WCF Sample:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://localhost/ServiceHelloWCF"xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:i0="http://tempuri.org/"xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing"xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" name="ServiceHelloWCF"targetNamespace="http://localhost/ServiceHelloWCF">
 <wsdl:import namespace="http://tempuri.org/" location="http://localhost:22082/ServiceHelloWCF.svc?wsdl=wsdl0"/>
 <wsdl:types>
 <xsd:schema targetNamespace="http://localhost/ServiceHelloWCF/Imports">
 <xsd:import schemaLocation="http://localhost:22082/ServiceHelloWCF.svc?xsd=xsd0" namespace="http://localhost/ServiceHelloWCF"/>
 <xsd:import schemaLocation="http://localhost:22082/ServiceHelloWCF.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
 </xsd:schema>
 </wsdl:types>
 <wsdl:message name="IServiceHelloWCF_HelloWCF_InputMessage">
 <wsdl:part name="parameters" element="tns:HelloWCF"/>
 </wsdl:message>
 <wsdl:message name="IServiceHelloWCF_HelloWCF_OutputMessage">
 <wsdl:part name="parameters" element="tns:HelloWCFResponse"/>
 </wsdl:message>
 <wsdl:portType name="IServiceHelloWCF">
 <wsdl:operation name="HelloWCF">
 <wsdl:input wsaw:Action="http://localhost/ServiceHelloWCF/IServiceHelloWCF/HelloWCF" message="tns:IServiceHelloWCF_HelloWCF_InputMessage"/>
 <wsdl:output wsaw:Action="http://localhost/ServiceHelloWCF/IServiceHelloWCF/HelloWCFResponse" message="tns:IServiceHelloWCF_HelloWCF_OutputMessage"/>
 </wsdl:operation>
 </wsdl:portType>
 <wsdl:service name="ServiceHelloWCF">
 <wsdl:port name="BasicHttpBinding_IServiceHelloWCF" binding="i0:BasicHttpBinding_IServiceHelloWCF">
 <soap:address location="http://localhost:22082/ServiceHelloWCF.svc"/>
 </wsdl:port>
 </wsdl:service>
 </wsdl:definitions>

The main difference I see is that you are using an endpoint with different binding than the one in the example. Change the binding to WSHttpBinding and see if it will work that way.

Hello Architect,

and thank you for your answer…

I’m working with Cedric on this matter and I’ve tryed this :

I had :


 <service name="ServiceHelloWCF.ServiceHelloWCF">
        <endpoint address="soap12" binding="wsHttpBinding" contract="ServiceHelloWCF.IServiceHelloWCF"/>
 </service>

to have the wsHttp, so now it generates :


<wsdl:service name="ServiceHelloWCF">
  <wsdl:port name="WSHttpBinding_IServiceHelloWCF" binding="i0:WSHttpBinding_IServiceHelloWCF">
    <soap12:address location="http://localhost:22082/ServiceHelloWCF.svc/soap12"/>
    <wsa10:EndpointReference>
     <wsa10:Address>http://localhost:22082/ServiceHelloWCF.svc/soap12</wsa10:Address>
        <Identity xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
          <Upn>PC-DE-KTAYFUN\TAYFUN</Upn>
       </Identity>
     </wsa10:EndpointReference>
   </wsdl:port>
</wsdl:service>

So we do have the WsHttpBinding, but is also add an identity/Upn with myself.

and off course, my client still have an IO:Exception on its request…

So we are ready to try anything if something comes to your mind…

Thanks again !!

Hey Tayfun and Cedric

I have same problem has you, have you found a solution…?

/Allan

@ Allan

There are several things that have to match to get DPWS & WCF I use the binding below to talk to DPWS. I also wrote this article to walk through discovery: https://www.ghielectronics.com/community/forum/topic?id=12582

Nick


WSHttpBinding wsHttpBinding = new WSHttpBinding();
                    wsHttpBinding.OpenTimeout = TimeSpan.FromMinutes(1);
                    wsHttpBinding.CloseTimeout = TimeSpan.FromMinutes(1);
                    wsHttpBinding.ReceiveTimeout = TimeSpan.FromMinutes(10);
                    wsHttpBinding.SendTimeout = TimeSpan.FromMinutes(1);
                    wsHttpBinding.BypassProxyOnLocal = false;
                    wsHttpBinding.TransactionFlow = false;
                    wsHttpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
                    wsHttpBinding.MaxBufferPoolSize = 524288;
                    wsHttpBinding.MaxReceivedMessageSize = 65536;
                    wsHttpBinding.MessageEncoding = WSMessageEncoding.Text;
                    wsHttpBinding.UseDefaultWebProxy = true;
                    wsHttpBinding.AllowCookies = false;
                    wsHttpBinding.ReaderQuotas.MaxDepth = 32;
                    wsHttpBinding.ReaderQuotas.MaxStringContentLength = 8192;
                    wsHttpBinding.ReaderQuotas.MaxArrayLength = 16834;
                    wsHttpBinding.ReaderQuotas.MaxBytesPerRead = 4096;
                    wsHttpBinding.ReaderQuotas.MaxNameTableCharCount = 16384;
                    wsHttpBinding.ReliableSession.Ordered = true;
                    wsHttpBinding.ReliableSession.InactivityTimeout = TimeSpan.FromMinutes(10);
                    wsHttpBinding.ReliableSession.Enabled = false;
                    wsHttpBinding.Security.Mode = SecurityMode.None;
                    wsHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                    wsHttpBinding.Security.Message.ClientCredentialType = MessageCredentialType.None;
                    wsHttpBinding.Security.Message.NegotiateServiceCredential = false;

                    return wsHttpBinding;