tags:

views:

58

answers:

2

I'm trying to build a web service using WCF. Since the service will ultimately be consumed by non-.net languages, I've been attempting to test it using "Add Web Reference" or using WSDL.exe instead of the svcutil way. I've been getting the following errors though:

From WSDL.exe - Error: Unable to import binding BasicHttpBinding_IEchoService from namespace http://tempuri.org. - - Unable to import operation Echo. - - The element http://tempuri.org/:Echo is missing.

From Add Service Reference and Add Web Reference: Metadata contains a reference that cannot be resolved: link to wsdl. The WSDL document contains links that could not be resolved. There was an error downloading http://localhost:8080/EchoService.svc?xsd=xsd0 The underlying connection was closed.

This simplified example has the same issue as the primary service.

Here's the service's Web.Config:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="EchoBehaviorConfiguration">
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service name="EchoService">
        <endpoint address="" 
                  behaviorConfiguration="EchoBehaviorConfiguration" 
                  binding="basicHttpBinding" 
                  contract="IEchoService" />
        <endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding" />

      </service>
    </services>
    <bindings>
      <basicHttpBinding>
      </basicHttpBinding>
      <mexHttpBinding></mexHttpBinding>
    </bindings>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

Here's the contract/interface:

[ServiceContract]
public interface IEchoService
{
    [OperationContract]
    string Echo(string message);
}

And here's the WSDL that is generated:

<wsdl:definitions name="EchoService" targetNamespace="http://tempuri.org/"&gt;
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports"&gt;
<xsd:import schemaLocation="http://localhost:8080/EchoService.svc?xsd=xsd0" namespace="http://tempuri.org/"/&gt;
<xsd:import schemaLocation="http://localhost:8080/EchoService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/&gt;
</xsd:schema>
</wsdl:types>
<wsdl:message name="IEchoService_Echo_InputMessage">
<wsdl:part name="parameters" element="tns:Echo"/>
</wsdl:message>
<wsdl:message name="IEchoService_Echo_OutputMessage">
<wsdl:part name="parameters" element="tns:EchoResponse"/>
</wsdl:message>
<wsdl:portType name="IEchoService">
<wsdl:operation name="Echo">
<wsdl:input wsaw:Action="http://tempuri.org/IEchoService/Echo" message="tns:IEchoService_Echo_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IEchoService/EchoResponse" message="tns:IEchoService_Echo_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IEchoService" type="tns:IEchoService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/&gt;
<wsdl:operation name="Echo">
<soap:operation soapAction="http://tempuri.org/IEchoService/Echo" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="EchoService">
<wsdl:port name="BasicHttpBinding_IEchoService" binding="tns:BasicHttpBinding_IEchoService">
<soap:address location="http://localhost:8080/EchoService.svc"/&gt;
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

The service is currently hosted locally via IIS7. I have attempted both HTTP and HTTPS and have the same issue. If I try to chang the binding from basicHttpBinding to webHttpBinding, nothing changes in the WSDL.

Any ideas on where I'm going wrong?

UPDATE: I have the configuration now setup that if the service is running under Cassini instead of IIS, I can add service or web references to my test project. I cannot save the wsdl and use WSDL.exe to generate the proxy classes though.

So now I have 3 issues:

  1. Other than doing an aspnet_regiis to install and register WCF 4 with IIS, is there anything else I may have to do?

  2. Any idea what I need to do in order to get it working with WSDL.exe?

  3. After doing an ASMX service and comparing the WSDLs generated, they are dramatically different which makes me question how compatible WCF is at this point with non-.net languages.

A: 

Given your example, I think you can simplify your configuration some.

For example, if you have the .svc file, which it looks like in your wsdl's enpoint declaration, you can have:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

then you should be able to access it via the url http://localhost:8080/EchoService.svc (assuming that it is on the local machine and listening on port 8080. Just thinking that Tomcat sometimes uses 8080 as its default port....)

Bryce Fischer
I tried that and it still isn't working. It's producing the same error messages. I had the serviceMetadata and serviceDebut in the example above but SO won't seem to show it for the life of me.
JamesEggers
what happens if you type http://localhost:8080/EchoService.svc in your browser, assuming that IIS is running along with your service (and that it is listening on port 8080)?
Bryce Fischer
I can view the wsdl in the browser when the service is hosted through IIS.
JamesEggers
When I attempt to reference the service via Add Service Reference in vs2010, I get the following:Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:8080/EchoService.svc. The client and service bindings may be mismatched.
JamesEggers
Further on the message reads:The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
JamesEggers
+1  A: 

Looks like you have not specified the behavior name in the correct place

http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.aspx

The result being that httpGet is not enabled for metadata.

Shiraz Bhaiji
After changing that, I now get an error saying that the content type of application/soap+xml was not the expected type text/xml.
JamesEggers
Was it the other way around, that expected was soap and you got text? If so you probably got an error message back instead of the contract.
Shiraz Bhaiji
Yes I got an error message back. I just don't know how to fix this since I'm using basicHttpBinding.The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.
JamesEggers