0

IIS でホストされている WCF Web サービスがあります。それは2人の消費者から始まりました。

1) IDE で WCF コントラクトをテストするための同じソリューション内の WinForm テスト ハーネス。

2) 公開されたバージョンを使用している Asp.Net Web アプリ。

いわば、すべてが箱から出して機能していました。

その後、3 番目のコンシューマである Android アプリが登場しました。これを正しく消費するには、WCF コントラクトを JSON WebGets と Webinvokes で装飾し、WCF Web.config を適切に変更する必要がありました。

これで、元の 2 つのコンシューマーは機能しなくなりました。したがって、Web.config や App.configs を変更して、3 つすべてが機能する構成を取得する必要があります。

最初に IDE に焦点を当てます。WCF サービス Web.Config の次のサービス モデル セクションがあります。

<system.serviceModel>
  <client>
    <endpoint binding="webHttpBinding" bindingConfiguration="JsonBinding"
              contract="CouponParkingWCF.ICouponService" name="Json" 
              kind="" endpointConfiguration="">
      <identity>
        <certificateReference storeName="My" storeLocation="LocalMachine"
                              x509FindType="FindBySubjectDistinguishedName" />
      </identity>
    </endpoint>
    <endpoint address="http://localhost:8707/CouponParking.svc"
              binding="basicHttpBinding" contract="CouponParkingWCF.ICouponService"
              name="BasicHttpBinding_ICouponService" />
  </client>
  <bindings>
    <basicHttpBinding>
      <binding name="basicHttp" />
    </basicHttpBinding>
    <webHttpBinding>
      <binding name="JsonBinding" />
    </webHttpBinding>
  </bindings>
  <services>
    <service name="CouponParkingWCF.CouponService">
      <endpoint behaviorConfiguration="JsonBehavior" binding="webHttpBinding"
                bindingConfiguration="" name="jsonEndPoint"
                contract="CouponParkingWCF.ICouponService" />
    </service>
  </services>
  <behaviors>
    <endpointBehaviors>
      <behavior name="JsonBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
  </protocolMapping>    
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                             multipleSiteBindingsEnabled="false" />
</system.serviceModel>

WinForm テスト ハーネス App.config には次のものが含まれます。

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttp" />
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://localhost:8707/CouponParking.svc"
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttp" 
              contract="CouponParking.ICouponService"
              name="BasicHttpBinding_ICouponService" />
  </client>
</system.serviceModel>

私はエンドポイントを構成する経験がなく、上記は例と当て推量に基づいています。

テスト ハーネスを実行すると、wcf クライアントはインスタンス化されますが、コントラクトの呼び出しは次のエラーで失敗します。

There was no endpoint listening at http://localhost:8707/CouponParking.svc 
that could accept the message. This is often caused by an incorrect address
or SOAP action. See InnerException, if present, for more details."

内部例外は次のとおりです。

{"The remote server returned an error: (404) Not Found."}
[System.Net.WebException]: {"The remote server returned an error: (404) Not Found."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
HResult: -2146233079
InnerException: null
Message: "The remote server returned an error: (404) Not Found."
Source: "System"
StackTrace: "   at System.Net.HttpWebRequest.GetResponse()\r\n   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)"
TargetSite: {System.Net.WebResponse GetResponse()}

私が間違っていることについてのガイダンスをいただければ幸いです。

ありがとう

4

2 に答える 2

4

一見すると、サービスの構成ファイルでクライアント エンドポイントとサービス エンドポイントを混同しているように見えます。サービス自体が別のサービスを呼び出していない限り、クライアント エンドポイントがサービスの構成ファイルに表示される理由はありません。

WinForm の構成ファイルは でクライアントを定義していますが、サービスエンドポイントをでbasicHttpBinding公開していません。これが、発生しているエラーの原因である可能性が最も高いです。BasicHttpBinding

<services>サービスの構成ファイルでクライアント エンドポイントを削除して、次のようにセクションに追加してみます。

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="basicHttp" />
    </basicHttpBinding>
    <webHttpBinding>
      <binding name="JsonBinding" />
    </webHttpBinding>
  </bindings>
  <services>
    <service name="CouponParkingWCF.CouponService">
      <endpoint address="SOAP"
                binding="basicHttpBinding" 
                contract="CouponParkingWCF.ICouponService"
                name="BasicHttpBinding_ICouponService" />
      <endpoint address="JSON"
                binding="webHttpBinding" bindingConfiguration="JsonBinding"
                contract="CouponParkingWCF.ICouponService" name="Json" 
                kind="" endpointConfiguration="">
        <identity>
          <certificateReference storeName="My" storeLocation="LocalMachine"
                                x509FindType="FindBySubjectDistinguishedName" />
        </identity>
      </endpoint>
    </service>
  </services>

WCF の ABC を思い出してください。A = アドレス、B = バインディング、C = コントラクト - これら 3 つの項目がサービスを定義します。

テスト ハーネスまたは ASP.NET アプリケーションとは異なるバインディングを必要とするクライアントを追加したため、そのバインディングで 2 番目のエンドポイントを公開する必要があります。

編集済み

@marc_s が指摘したように、2 つの異なる相対アドレスが必要になります。それを反映するように構成ファイルを更新しました。

私自身は複数のエンドポイントを使用する機会がありませんでしたが *.svc ファイルの場所によって提供されるベース アドレスを使用して、次のように使用すると思います。

http://localhost:8707/CouponParking.svc/SOAP
http://localhost:8707/CouponParking.svc/JSON

最初は 用でBasicHttpBinding、2 番目は 用WebHttpBindingです。

于 2013-08-24T06:17:29.393 に答える
3

基本的に、 (SOAP バインディング) とAndroid クライアント用 (REST バインディング)の両方を提供するには、2 つの別個のエンドポイントが必要です。basicHttpBindingwebHttpBinding

サービスの「ベース」アドレスは、IIS 仮想ディレクトリと*.svcファイルが存在する場所 ( http://localhost:8707/CouponParking.svc) によって定義されます。したがって、この「ベース」アドレスと定義された相対アドレスで両方のサービスに到達できます。

したがって、これを次のように構成する必要があります。

<services>
   <service name="CouponParkingWCF.CouponService">
      <!-- define the basicHttp (SOAP) endpoint at the base address -->
      <endpoint name="SoapEndpoint"
          address=""
          binding="basicHttpBinding" 
          contract="CouponParkingWCF.ICouponService" />
      <!-- define the REST endpoint at (base)+"/rest" -->
      <endpoint name="RestEndpoint"
          address="rest"
          behaviorConfiguration="JsonBehavior" 
          binding="webHttpBinding" 
          contract="CouponParkingWCF.ICouponService" />
   </service>
</services>

basicHttpBindingこのセットアップでは、 (SOAP) を使用してサービスを呼び出すことができるはずです。

http://yourServer:8707/CouponParking.svc

REST ベースの JSON 対応エンドポイントにアクセスできるはずです。

http://yourServer:8707/CouponParking.svc/rest

両方のサーバー側エンドポイントは同じサービス コードによって処理されます。異なるのは、エンドポイント (およびエンドポイントが理解するプロトコル) だけです。

于 2013-08-24T07:42:22.260 に答える