1

私はSOAPを訴える単純なWCFサービスを持っています。非常に少量のデータで非常に単純な操作「GetMultiplied」があります。クライアントが操作を呼び出そうとすると、次の例外が発生します。何が問題になるのか、何か考えはありますか?

内部例外:{"リモートサーバーがエラーを返しました:(400)不正な要求。"}

完全なwsdlとスキーマが最後にリストされています。

注:サービス構成とクライアント構成の両方で、クォータ値、maxBufferSizeなどをより高い値に設定しました。

サービス中のトレース

サービスでトレースを使用した場合( WCFトレースをオンにする方法に基づく)、次のようになります-エラーがログに記録されていないようです。

<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>

サービスの実装

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;
    }
}

クライアント

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

自動生成されたコードの詳細は次のとおりです。

    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(自動生成)

<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>
4

1 に答える 1

2

私は問題を解決しました:-)

他の人の利益のために回答を公開します。

  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. (localhost の代わりに) サービスに相対パスを使用するエラー「指定されたアドレスに一致するプロトコル バインディングがありません ...」

  5. サービス トレースも役に立ちます (ただし、ここでは役に立ちませんでした)。「C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\SvcTraceViewer.exe」を使用しました。投稿に従うと、エラー ファイル (initializeData="Error.svclog") がソリューション プロジェクト内に保存されます。他の場所に変更しても機能しませんでした。WCF トレースを有効にする方法は?

  6. 参照1 つの WCF サービス – 2 つのクライアント。1 つのクライアントが機能しない

于 2012-09-14T04:42:54.090 に答える