tags:

views:

1952

answers:

4

One of my methods returns byte[], of a file. All other methods return either string objects or custom objects

I can view the WSDL via a browser and as i have used WCfExtras, I can even view the documentation.

In my test app, C# web application, I add the reference to my svc, hosted on a test server. I get an error as such:

     The document was understood, but it could not be processed.
  - The WSDL document contains links that could not be resolved.
  - There was an error downloading ...
  - Unable to connect to remote server
  - No connection could be made because the target machine actively refused it

    Content Type application/soap+xml; charset=utf-8 was not supported by service .  The client and service bindings may be mismatched.
    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'..
    If the service is defined in the current solution, try building the solution and adding the service reference again.

This is my app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="TestApp.Properties.Settings.TestDBConnectionString"
      connectionString="Data Source=192.168.2.130;Initial Catalog=TestDB;Persist Security Info=True;User ID=sa;Password=xerox"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="TestApp.Service1Behavior"
        name="TestApp.SearchService">
        <endpoint address="" behaviorConfiguration="Sample.WsdlSampleEndpointBehavior"
          binding="basicHttpBinding" bindingConfiguration="WsHttpMtomBinding" contract="TestApp.ISearchService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/TestApp/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
       <endpointBehaviors>
        <behavior name="Sample.WsdlSampleEndpointBehavior">
          <wsdlExtensions location="http://localhost:8731/TestApp/Service1/"/&gt;
        </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
        <behavior name="TestApp.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="true" />
        </behavior>

      </serviceBehaviors>
    </behaviors>
    <extensions>
      <behaviorExtensions>
        <!-- Declare that we have an extension called WSDL Extras-->
        <add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
      </behaviorExtensions>
    </extensions>
    <bindings>
      <basicHttpBinding>
        <binding name="WsHttpMtomBinding" messageEncoding="Mtom" transferMode="StreamedResponse" />
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

Any ideas on how I would resolve this? Should I have 2 different bindings, one for methods returning non bytes[] and Mtom for method returning byte[]? If so how does one apply bindings per method exposed?

Tried running it with WcfTestClient.exe and this is the error

rror: Cannot import wsdl:portTypeDetail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporterError: Schema with target namespace 'http://tempuri.org/' could not be found.XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISearchService']Error: Cannot import wsdl:bindingDetail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='ISearchService']XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_ISearchService']Error: Cannot import wsdl:portDetail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_ISearchService']XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='SearchService']/wsdl:port[@name='BasicHttpBinding_ISearchService']Warning: No code was generated.If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or servicesor because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata documents to the tool.Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option.
A: 

On the client app, do you have a reference to the WCFExtras assembly? The error appears to be saying that the binding is not recognized, which is, I assume, because of the extensions introduced by WCFExtras. Try adding the same extensions section to your client's config file as is in the server's config file.

Jacob
Jacob, I am using WCfTestClient.exe, part of VS2008 to try and invoke and use my service. Not sure how I would add that ref in WcfTestClient.exe
I meant that you could add the extension to your client application. I guess I was making an assumption that you're also writing a client for your web service, and your problem was that you could not add a reference to it. I'm not very familiar with WcfTestClient.exe.If you post the WSDL that's being generated, we might be able to more-easily help.
Jacob
Jacob, will post the WSDL by end of day or tomorrow once the servers is available to me.
A: 

Your binding is basicHttpBinding, but your binding configuration is wsHttpMTOMBinding.

This looks like a mismatch, however it could be just the names that you have given things.

Try opening the config file in the WCF config tool, this should tell you (refuse to open the file), if there are inconsistencies in your config file.

Hope this helps

Shiraz

Shiraz Bhaiji
Shiraz,I have 1 method that returns contents of file and its return type is Bytes[]. All my other methods return strings and ints and hence I went with Mtom binding configuration. Not sure if I can apply different binding configurations to methods that return large files as Bytes[] and different binding configurations to methods that return strings and ints
What I was trying to say was that you cannot combine basichttp and wshttp in the same endpoint. In one of our projects we have the same situation as you, there we have just used plain basichtttpbinding, with the message sizes set high enough. We have used this to send over files of upto 30MB. This is not as efficient as using MTOM, with respect to memory usage, but we had sufficient memory, so it was not a problem.I would suggest that you try using basichttp binding first, without MTOM. If you need MTOM, split the contract, and check that you use wshttpbinding.
Shiraz Bhaiji
A: 

This can't be a true answer, but after I removed WCfExtras references from my app.config file and deployed, things seem to work.

This is what I was trying to achieve, but have abandoned for time being

WCF Extras

If anyone has an idea of how and what I configured wrong, please advise on this column.

Many Thanks

A: 

The answer for me to be able to use the WCF Test Client is to set the set singleFile="true" in the web config like this.

<behavior name="Sample.WsdlSampleEndpointBehavior">
      <wsdlExtensions location="http://localhost:8731/TestApp/Service1/" singleFile="true" />
 </behavior>