0

文書化されていない Web サービスがあり、Visual C# で記述されたクライアントを使用して、この Web サービスのバージョンを取得する必要があります。問題は、私が初心者すぎることです。

Visual Studio にサービス リファレンスを追加したので、プロキシ ファイルと output.config ファイルを取得しました。

クラスの新しいインスタンスを開始するために、VS から次の行を取得します。

DentalScannerServiceClient client = new DentalScannerServiceClient();

だから私はこれを私のコンソールアプリに入れました:

DentalScannerServiceClient client = new DentalScannerServiceClient();
client.GetSoftwareVersion();

エラー「メソッド 'GetSoftwareVersion' のオーバーロードは 0 引数を取ります」を取得します。client.GetSoftwareVersion:

Status DentalScannerServiceClient.GetSoftwareVersion( out string version )

だから私はこのコードを試します:

    DentalScannerServiceClient client = new DentalScannerServiceClient();
    string oo;
    client.GetSoftwareVersion(out oo);

次に文字列を出力しますが、コードを実行すると次のエラーが発生します。

"InvalidOperationException was unhandled" "Could not find default endpoint element that references contract 'IDentalScannerService' in the ServiceModel client configuration section. これは、アプリケーションの構成ファイルが見つからなかったか、このコントラクトに一致するエンドポイント要素が見つからなかったためである可能性がありますクライアント要素。

これを解決する方法、またはどこから探し始めるかについてのアイデアはありますか? どんな助けにも感謝します。多分それは簡単なことです。私もC#の経験はほとんどありません。

app.config:

<?xml version="1.0"?>
<configuration>
<configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <section name="ThisIsTest.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    </sectionGroup>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><applicationSettings>
        <ThisIsTest.Properties.Settings>
            <setting name="ThisIsTest_localhost_DentalScannerService" serializeAs="String">
                <value>http://localhost:8731/DentalServiceLib/DentalScannerService/</value>
            </setting>
        </ThisIsTest.Properties.Settings>
    </applicationSettings>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicEndPoint" 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="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8731/DentalServiceLib/DentalScannerService/"
                binding="basicHttpBinding" bindingConfiguration="BasicEndPoint"
                contract="Scanner.IDentalScannerService" name="BasicEndPoint" />
        </client>
    </system.serviceModel>
</configuration>

output.config (これは wsdl.exe から取得し、 [プロジェクト] -> [既存の項目を追加] を実行して追加しました:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicEndPoint" 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="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8731/DentalServiceLib/DentalScannerService/"
                binding="basicHttpBinding" bindingConfiguration="BasicEndPoint"
                contract="IDentalScannerService" name="BasicEndPoint" />
        </client>
    </system.serviceModel>
</configuration>
4

2 に答える 2

0

この方法を機能させることができなかったので、別の方法で行いました。

  1. SDK で wsdl.exe によって生成された .wsdl ファイルを使用する
  2. soapUIをダウンロードし、wsdl ファイルを初期ファイルとして新しいプロジェクトを開始しました
  3. soapUI は、Web サービス内のすべてのオブジェクトに対する SOAP 要求を作成しました
  4. soapUI でさまざまな呼び出しをテストし、応答をライブで取得しました
  5. C# VS に入り、コンソール アプリで最初に Web サービスを開始し、次に HttpWebRequest を使用して単純な SOAP 要求を送信するようにしました
  6. ビンゴ

この方法は意外とうまくいきます!

于 2012-08-10T07:02:30.390 に答える
0

これは、構成ファイルにエンドポイントが複数回表示されていることが原因である可能性が最も高いです。セクションを見つけて、<system.serviceModel><client></client></system.serviceModel>重複をチェックします (名前に基づいて)

構成ファイルに client セクションがまったく存在しない場合は、追加する必要があります。このテンプレートに従ってください

<configuration>
    <system.serviceModel>
        <client>
            <endpoint address="<address here>" binding="basicHttpBinding" contract="<full qualifeid class name to client interface>" name="<some name here>" />
        </client>
    </system.serviceModel>
</configuration>
于 2012-08-08T14:40:49.477 に答える