Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
571 views
in Technique[技术] by (71.8m points)

c# - 400 Bad Request Exception: Simple SOAP WCF service with small data

I have a simple WCF service suing SOAP. I have a very simple operation “GetMultiplied “ with very small amount of data. I am getting following exception when client try to call the operation. Any idea what all could be the issues?

Inner Exception: {"The remote server returned an error: (400) Bad Request."}

Complete wsdl and schema is listed at the end.

Note: I have set quota values, maxBufferSize etc to higher values in both service and client config.

Tracing in Service

When I used tracing in service (based on How to turn on WCF tracing?), I am getting the following - seems like there is no error logged.

<Type>3</Type>
<SubType Name="Information">0</SubType>
<Level>8</Level>
<TimeCreated SystemTime="2012-09-13T17:05:17.6059181Z" />
<Source Name="System.ServiceModel" />
<Description>AppDomain unloading.</Description>

Service implementation

public class CalculationService : ICalculationService
{

    public virtual GetMultipliedResponse GetMultiplied(GetMultipliedRequest request)
    {
        MultipliedResult result = new MultipliedResult();
        result.ResultNumber= ((request.InputNumber)*2);

        GetMultipliedResponse response = new GetMultipliedResponse(result);
        return response;
    }
}

Client

    static void Main(string[] args)
    {
        CalculationServiceInterfaceClient proxy = new CalculationServiceInterfaceClient();
        multipliedResult result = proxy.getMultiplied(2);
    }

In the auto generated code the detail is:

    public NewClient.CalcReference.multipliedResult getMultiplied(int inputNumber) 
    {
        NewClient.CalcReference.getMultipliedRequest inValue = new NewClient.CalcReference.getMultipliedRequest();
        inValue.inputNumber = inputNumber;

        NewClient.CalcReference.getMultipliedResponse retVal = ((NewClient.CalcReference.CalculationServiceInterface)(this)).getMultiplied(inValue);
        return retVal.restaurants;
    }

WSDL

<definitions xmlns:import0="urn:lijo:demos:multiplyservice:messages:v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:import1="urn:lijo:demos:multiplyservice:data:v1" xmlns:tns="urn:lijo:demos:multiplyservice:calculation:v1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" name="CalculationService" targetNamespace="urn:lijo:demos:multiplyservice:calculation:v1" xmlns="http://schemas.xmlsoap.org/wsdl/">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
<types>
<xsd:schema>
  <xsd:import schemaLocation="C:oolboxLijosServiceAppNewServiceRestaurantMessages.xsd" namespace="urn:lijo:demos:multiplyservice:messages:v1" />
  <xsd:import schemaLocation="C:oolboxLijosServiceAppNewServiceRestaurantData.xsd" namespace="urn:lijo:demos:multiplyservice:data:v1" />
  </xsd:schema>
 </types>
 <message name="getMultipliedIn">
 <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
 <part name="parameters" element="import0:getMultiplied" />
 </message>
 <message name="getMultipliedOut">
 <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
 <part name="parameters" element="import0:getMultipliedResponse" />
 </message>
 <portType name="CalculationServiceInterface">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
  <operation name="getMultiplied">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
  <input message="tns:getMultipliedIn" />
  <output message="tns:getMultipliedOut" />
  </operation>
  </portType>
  <binding name="BasicHttpBinding_CalculationServiceInterface" type="tns:CalculationServiceInterface">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
  <operation name="getMultiplied">
  <soap:operation soapAction="urn:lijo:demos:multiplyservice:calculation:v1:getMultipliedIn" style="document" />
  <input>
    <soap:body use="literal" />
  </input>
  <output>
    <soap:body use="literal" />
  </output>
  </operation>
  </binding>
  <service name="CalculationServicePort">
  <port name="CalculationServicePort" binding="tns:BasicHttpBinding_CalculationServiceInterface">
  <soap:address location="http://localhost/CalculationService" />
  </port>
  </service>
  </definitions>

XSD

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="RestaurantData" targetNamespace="urn:lijo:demos:multiplyservice:data:v1"
elementFormDefault="qualified" xmlns="urn:lijo:demos:multiplyservice:data:v1"
xmlns:mstns="urn:lijo:demos:multiplyservice:data:v1" xmlns:xs="http://www.w3.org/2001/XMLSchema">

 <xs:complexType name="multipliedResult">
 <xs:sequence>
  <xs:element name="resultNumber" type="xs:int" />
 </xs:sequence>
 </xs:complexType>
 </xs:schema>

Cleint Config (Autogenerated)

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_CalculationServiceInterface"
                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="524288" maxStringContentLength="524288" maxArrayLength="524288"
                    maxBytesPerRead="524288" maxNameTableCharCount="524288" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost/CalculationService" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_CalculationServiceInterface"
            contract="CalcReference.CalculationServiceInterface" name="CalculationServicePort" />
    </client>
</system.serviceModel>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I solved the problem :-)

I will publish the answer for the benefit of others.

  1. Key problem: I was trying to use the manually created wsdl. (I reffered the local copy available inside service - I was using a tool to generate the service code from wsdl). The service was not providing it. I should have tried to view the wsdl from browsing the svc file

  2. Ran the service using WcfTestClient. Gave an error that revealed the project name and the namespace that we use should be same. (Otherwise it will append the project name before the namespace name and that will become incorrect namespace)

    Type the “WcfTestClient” command in “Visual Studio Command Prompt”. http://blogs.msdn.com/b/wcftoolsteamblog/archive/2010/01/04/tips-for-launching-wcf-test-client.aspx

  3. By browsing the svc file in the service, it showed that the metadata publishing is not enabled. Added a service behavior for meta data browsing in the web.config.

  4. Used relative path for the service (instead of localhost) error "No protocol binding matches the given address ..."

  5. Service Tracing also can be helpful (though did not help me here). Used "C:Program FilesMicrosoft SDKsWindowsv7.0AinSvcTraceViewer.exe". Followed the post and the Error file (initializeData="Error.svclog") is stored inside the solution project. Changing it to other locations did not work. How to turn on WCF tracing?

  6. Refer One WCF service – two clients; One client does not work


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...