2013-08-24 2 views
0

IIS 호스팅 WCF 웹 서비스가 있습니다. 그것은 두 명의 소비자로 시작되었습니다.WCF 끝점입니다. 여러 클라이언트

1) IDE에서 WCF 계약을 테스트하는 동일한 솔루션의 WinForm 테스트 도구.

2) 게시 된 버전을 사용하는 Asp.Net 웹 응용 프로그램.

모두 말하는 것처럼 상자에서 작동했습니다.

3 번째 소비자 인 Android 앱이 출시되었습니다. 이 작업을 올바르게 수행하려면 JSON WebGets 및 Webinvokes를 사용하여 WCF 계약을 장식하고 WCF Web.config를 변경해야합니다.

이제 원래의 두 소비자는 더 이상 작동하지 않습니다. 따라서 Web.config 및/또는 App.configs를 변경하여 세 가지 모두 작동하는 구성을 가져와야합니다.

먼저 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()} 

나는에 대한 몇 가지 지침을 부탁드립니다 내가 틀렸어.

감사

눈에서
+0

동일한 서비스를 다른 엔드 포인트 (예 : 바인딩이 다른 여러 클라이언트)에 동일한 엔드 포인트에서 표시하려고합니까? 그렇다면 그렇게 할 수 없습니다. 서로 다른 서비스 구현을 위해 다른 끝점을 노출해야합니다. – Tim

+0

또한 세 번째 클라이언트를 추가하기 전에 * 구성 파일을 게시 할 수 있습니까? 그것이 작동 할 때의 모습과 현재의 모습 (작동하지 않을 때)을 확인하는 데 도움이 될 수 있습니다. – Tim

+0

각 서버 측 끝점에는 ** 정의 된 바인딩이 하나 ** ** 있습니다. ** 첫 번째와 두 번째 클라이언트를위한'basicHttpBinding' (SOAP)을 지원하는 하나의 엔드 포인트를 가질 수없고, 동시에 안드로이드 클라이언트를위한'webHttpBinding' (REST)도 지원할 수 없다. ** 두 개의 별도 엔드 포인트 **를 사용해야합니다. –

답변

4

, 당신이 당신의 서비스의 설정 파일에 서비스 엔드 포인트와 클라이언트 엔드 포인트를 혼합 한 것으로 보인다. 서비스가 다른 서비스를 호출하는 경우가 아니면 서비스의 구성 파일에 클라이언트 엔드 포인트가 표시 될 이유가 없습니다.

당신의 WinForm의 설정 파일은 basicHttpBinding와 클라이언트를 정의하는,하지만 당신은 가장 가능성이 당신이지고있는 오류의 원인이다 BasicHttpBinding서비스 엔드 포인트를 노출시키지 마십시오.

나는 서비스의 config 파일에서 클라이언트 엔드 포인트를 삭제하려고,이처럼 <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> 

ABC의 WCF의 기억 : = 주소, B를 = 바인딩 및 C = 계약 -이 세 항목은 서비스를 정의합니다.

테스트 하네스 또는 ASP.NET 응용 프로그램과 다른 바인딩이 필요한 클라이언트를 추가 했으므로 해당 바인딩으로 두 번째 끝점을 노출해야합니다.

@marc_s가 지적한 것처럼, 당신은 두 가지 상대 주소가 필요합니다

편집했다. 이를 반영하기 위해 config 파일을 업데이트했습니다.

여러 개의 엔드 포인트 나 자신을 사용할 수있는 기회가 없었습니다,하지만 난 * SVC는 파일의 위치에 의해 제공되는 당신이 기본 주소로, 그들에게이 방법을 사용하는 거라고 생각 :

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

첫 번째 것은 BasicHttpBinding이고 두 번째는 WebHttpBinding입니다.

+0

정의하려는 두 개의 엔드 포인트에 대해 두 개의 다른 주소를 제공해야합니다. 그들의 "기본"주소는 IIS 가상 디렉터리와'* .svc' 파일의 위치에 의해 정의됩니다. 이제 두 끝점을 구별하기 위해 두 개의 고유 한 상대 주소가 필요합니다 .... –

+1

@marc_s - 감사합니다. 나는 당신이 말한 것에 대한 나의 이해를 반영하여 나의 대답을 업데이트했다. 그래도 오류가 있다면 알려주세요. – Tim

+0

감사합니다 Tim, 당신과 marc_s는 해결책뿐만 아니라 명확한 설명을 제공했습니다. 귀하의 답변은 marc_s 앞에 오므로 귀하를 답변으로 표시했습니다. –

3

당신은 기본적으로 그냥 basicHttpBinding (바인딩 SOAP)와 안드로이드 클라이언트에 대한 webHttpBinding (A REST 바인딩)을 모두 제공하는 두 개의 엔드 포인트이 필요합니다.

"기본"을 서비스의 주소가 당신의 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> 

이 설정으로를, 당신은

http://yourServer:8707/CouponParking.svc 
에서 basicHttpBinding (SOAP)를 사용하여 서비스를 호출 할 수 있어야한다

하고

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

모두 서버 측 엔드 포인트가 동일한 서비스 코드에 의해 처리됩니다에서 REST 기반의 JSON 기반 엔드 포인트에 액세스 할 수 있어야합니다은 - 그냥 엔드 포인트 (및 프로토콜의 그 엔드 포인트 이해)

+0

당신과 팀 모두 돈을 벌고 있습니다. 팀의 첫 번째 답변으로 팀의 마크를 표시했습니다. 솔루션뿐만 아니라 설명을 주셔서 감사합니다. –