400错误请求例外:数据量小的简单的SOAP WCF服务 [英] 400 Bad Request Exception: Simple SOAP WCF service with small data

查看:109
本文介绍了400错误请求例外:数据量小的简单的SOAP WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的WCF服务起诉的 SOAP 。我有一个非常简单的操作GetMultiplied的数据量非常小。我得到以下异常时,客户端尝试调用操作。 ?任何想法都可能成为问题。




内部异常:{远程服务器返回错误:(400)错误的请求。 }




完整的WSDL和架构在年底上市。



请注意:我已经设置配额值,MAXBUFFERSIZE等在两个服务端和客户端的配置较高的值



跟踪在服务



当我在使用跟踪服务(基于如何?打开WCF跟踪),我得到了以下 - 好像是没有记录的错误

 <。 ;类型>第3版; /型号> 
<类型名称=信息> 0℃; /亚型GT;
<平> 8示/平>
< TimeCreated SYSTEMTIME =2012-09-13T17:05:17.6059181Z/>
<信源名称=System.ServiceModel/>
<说明方式>的AppDomain卸载< /说明>



服务实施



 公共类CalculationService:ICalculationService 
{

公共虚拟GetMultipliedResponse GetMultiplied(GetMultipliedRequest要求)
{
MultipliedResult结果=新MultipliedResult();
result.ResultNumber =((request.InputNumber)* 2);

GetMultipliedResponse响应=新GetMultipliedResponse(结果);
返回响应;
}
}



客户端

 静态无效的主要(字串[] args)
{
CalculationServiceInterfaceClient代理=新CalculationServiceInterfaceClient();
multipliedResult结果= proxy.getMultiplied(2);
}

在自动生成的代码的细节是:



 公共NewClient.CalcReference.multipliedResult getMultiplied(INT inputNumber)
{
NewClient.CalcReference.getMultipliedRequest inValue =新NewClient.CalcReference.getMultipliedRequest ();
inValue.inputNumber = inputNumber;

NewClient.CalcReference.getMultipliedResponse retVal的=((NewClient.CalcReference.CalculationServiceInterface)(本))getMultiplied(inValue)。
返回retVal.restaurants;
}



WSDL



 <定义的xmlns:import0 =瓮:lijo:演示:multiplyservice:消息:V1的xmlns:XSD =htt​​p://www.w3.org / 2001 / XML模式的xmlns:import1 =瓮:lijo:演示:multiplyservice:数据:V1的xmlns:TNS =瓮:lijo:演示:multiplyservice:计算:V1的xmlns:SOAP =HTTP://模式。 xmlsoap.org/wsdl/soap/的xmlns:SOAP12 =http://schemas.xmlsoap.org/wsdl/soap12/NAME =CalculationService的targetNamespace =瓮:lijo:演示:multiplyservice:计算:V1的xmlns =htt​​p://schemas.xmlsoap.org/wsdl/> 
< WSDL:文档的xmlns:WSDL =htt​​p://schemas.xmlsoap.org/wsdl//>
<各类>
< XSD:架构>
< XSD:导入的schemaLocation =C:\toolbox\LijosServiceApp\NewService\RestaurantMessages.xsd命名空间=瓮:lijo:演示:multiplyservice:消息:V1/>
< XSD:导入的schemaLocation =C:\toolbox\LijosServiceApp\NewService\RestaurantData.xsd命名空间=瓮:lijo:演示:multiplyservice:数据:V1/>
< / XSD:架构>
< /类型>
<消息名称=getMultipliedIn>
< WSDL:文档的xmlns:WSDL =htt​​p://schemas.xmlsoap.org/wsdl//>
<部分名称=参数元素=import0:getMultiplied/>
< /消息>
<消息名称=getMultipliedOut>
< WSDL:文档的xmlns:WSDL =htt​​p://schemas.xmlsoap.org/wsdl//>
<部分名称=参数元素=import0:getMultipliedResponse/>
< /消息>
<端口类型名称=CalculationServiceInterface>
< WSDL:文档的xmlns:WSDL =htt​​p://schemas.xmlsoap.org/wsdl//>
<操作NAME =getMultiplied>
< WSDL:文档的xmlns:WSDL =htt​​p://schemas.xmlsoap.org/wsdl//>
<输入消息=TNS:getMultipliedIn/>
<输出消息=TNS:getMultipliedOut/>
< /运转>
< /端口类型>
<绑定名称=BasicHttpBinding_CalculationServiceInterfaceTYPE =TNS:CalculationServiceInterface>
<肥皂:绑定传输=htt​​p://schemas.xmlsoap.org/soap/http/>
<操作NAME =getMultiplied>
<肥皂:操作的soapAction =瓮:lijo:演示:multiplyservice:计算:V1:getMultipliedIn的风格=文件/>
<输入>
<肥皂:身体使用=文字/>
< /输入>
<输出>
<肥皂:身体使用=文字/>
< /输出GT;
< /运转>
< /&结合GT;
<服务名称=CalculationServicePort>
<港口名称=CalculationServicePort绑定=TNS:BasicHttpBinding_CalculationServiceInterface>
<肥皂:地址位置=HTTP://本地主机/ CalculationService/>
< /端口>
< /服务>
< /定义>



XSD



 <?XML版本=1.0编码=UTF-8>?; 
< XS:模式ID =RestaurantData的targetNamespace =瓮:lijo:演示:multiplyservice:数据:V1
将elementFormDefault =合格的xmlns =金塔:lijo:演示:multiplyservice:数据:V1
的xmlns:mstns =瓮:lijo:演示:multiplyservice:数据:V1的xmlns:XS =http://www.w3.org/2001/XMLSchema>

< XS:复杂类型名称=multipliedResult>
< XS:序列>
< XS:元素的名称=resultNumber类型=XS:INT/>
< / XS:序列>
< / XS:复杂类型>
< / XS:架构>



Cleint配置(自动生成)

 < system.serviceModel> 
<&绑定GT;
<&basicHttpBinding的GT;
<绑定名称=BasicHttpBinding_CalculationServiceInterface
closeTimeout =00:01:00openTimeout =00:01:00receiveTimeout =00:10:00
的SendTimeout = 00:01:00allowCookies =假bypassProxyOnLocal =false的
hostNameComparisonMode =StrongWildcardMAXBUFFERSIZE =65536
maxBufferPoolSize =524288maxReceivedMessageSize =6​​5536
messageEncoding = 文本textEncoding =UTF-8transferMode =缓冲
useDefaultWebProxy =真正的>
< readerQuotas MAXDEPTH =524288maxStringContentLength =524288maxArrayLength =524288
maxBytesPerRead =524288maxNameTableCharCount =524288/>
<安全模式=无>
<运输clientCredentialType =无proxyCredentialType =无
境界=/>
<消息clientCredentialType =用户名algorithmSuite =默认/>
< /安全>
< /&结合GT;
< / basicHttpBinding的>
< /绑定>
<客户端>
<端点地址=HTTP://本地主机/ CalculationService绑定=basicHttpBinding的
bindingConfiguration =BasicHttpBinding_CalculationServiceInterface
合同=CalcReference.CalculationServiceInterfaceNAME =CalculationServicePort/> ;
< /客户>
< /system.serviceModel>


解决方案

我的问题解决了:-)



我将公布为他人的利益,答案




  1. 关键问题:我试图用手动创建的WSDL。 (我下文称本地副本里面提供服务 - 我使用的工具来生成从WSDL服务代码)。该服务没有提供它。我应该尝试从浏览SVC文件来查看WSDL


  2. 使用的 WcfTestClient 冉服务。给了显露在项目名称,我们使用应该是相同的命名空间中的错误。 (否则将追加命名空间名称前的项目名称,这将成为不正确的命名空间)



    在Visual Studio命令提示符中的WcfTestClient命令。 的http:/ /blogs.msdn.com/b/wcftoolsteamblog/archive/2010/01/04/tips-for-launching-wcf-test-client.aspx


  3. 通过用户在服务的SVC文件,它表明,在元数据发布未启用。增加了在web.config元数据浏览的服务行为


  4. 有关服务(而不是本地主机)的error [否协议绑定指定的地址匹配..."


  5. 服务跟踪也有帮助(虽然并没有帮助我在这里)。使用C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\SvcTraceViewer.exe。其次岗位和错误文件(initializeData =Error.svclog)存储解决方案项目中。它更改到其他地点没有工作。 如何打开WCF跟踪?


  6. 请参照的一个WCF服务 - 两个客户端;一个客户端不能正常工作



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:\toolbox\LijosServiceApp\NewService\RestaurantMessages.xsd" namespace="urn:lijo:demos:multiplyservice:messages:v1" />
  <xsd:import schemaLocation="C:\toolbox\LijosServiceApp\NewService\RestaurantData.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>

解决方案

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 Files\Microsoft SDKs\Windows\v7.0A\bin\SvcTraceViewer.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

这篇关于400错误请求例外:数据量小的简单的SOAP WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆