2013-12-13 5 views
0

바이트 배열을 보내려고 할 때 잘못된 요청 오류가 발생합니다. 모든 메시지 제한에 대한 최대 값을 확인했습니다. 모두 최대 값으로 설정됩니다. 그러나 바이트 배열 매개 변수를 null로 유지하여 서비스 메서드에 문자열 값을 보낼 수 있습니다. 왜 이런 일이 일어나는지 모르겠습니다. 또한 서비스 동작 구성 이름과 바인딩 구성 이름 (즉, 포함 된 네임 스페이스)을 확인했습니다. 도움이된다면 큰 도움이 될 것입니다.비누를 사용하여 wcf에 바이트 배열 전달

.... 
ServiceClient ac = new ServiceClient(); 
string ServiceUrl = "http://localhost:20314/Service.svc"; 
EndpointAddress address = new EndpointAddress(ServiceUrl); 
BasicHttpBinding httpbinding = new BasicHttpBinding(); 
using (ChannelFactory<IServiceChannel> factory = new ChannelFactory<IServiceChannel>(httpbinding)) 
{ 
    factory.Endpoint.Address = address; 
    using (IServiceChannel oService = factory.CreateChannel()) 
    { 

     using (OperationContextScope scope = new OperationContextScope(oService)) 
     { 

     Guid myToken = new Guid("guid here");      

     MessageHeader<Guid> mhg = new MessageHeader<Guid>(myToken);      
     MessageHeader untyped = mhg.GetUntypedHeader("identity", "ns"); 
     OperationContext.Current.OutgoingMessageHeaders.Add(untyped); 
     // here i am getting bad request error                
     var fdt = (oService).GetData(bytearray, value); 

     } 
    } 
} 
....... 

클라이언트 웹 설정 :

이 내 클라이언트 측 코드

<system.web> 
<compilation debug="true" targetFramework="4.0"/>  
<httpRuntime maxRequestLength="500000000" executionTimeout="360"/> 
</system.web> 
<system.serviceModel> 
<bindings> 
    <basicHttpBinding>   
    <binding name="BasicHttpBinding_IService" closeTimeout="01:01:00" 
     openTimeout="01:01:00" receiveTimeout="01:10:00" sendTimeout="01:01:00" 
     allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
     maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
     messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
     useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
     maxBytesPerRead="4096" maxNameTableCharCount="2147483647" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
      realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

<client>  
    <endpoint address="http://localhost:20314/Service.svc" binding="basicHttpBinding" 
    bindingConfiguration="BasicHttpBinding_IService" contract="LocalService.IService" 
    name="BasicHttpBinding_IService"/> 
</client> 

<services>  
    <service name="LocalService.Service" behaviorConfiguration="ServiceBehavior"> 
    <endpoint address="http://localhost:20314/Service.svc" binding="wsHttpBinding" contract="LocalService.IService" /> 
    </service> 
</services> 

<behaviors> 
    <serviceBehaviors>   
    <behavior name="ServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

서비스 웹 구성

<system.web> 
<compilation debug="true" targetFramework="4.0" /> 
<httpRuntime maxRequestLength="500000000" executionTimeout="360"/> 
</system.web> 
<system.webServer> 
<httpErrors errorMode="Detailed" /> 
<asp scriptErrorSentToBrowser="true" /> 
</system.webServer> 
<system.serviceModel>  
<behaviors> 
    <serviceBehaviors> 
    <behavior>   
     <serviceAuthorization serviceAuthorizationManagerType="ServiceApp.APIKeyAuthorization, ServiceApp" /> 
     <serviceMetadata httpGetEnabled="true" /> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
     <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<standardEndpoints> 
    <webHttpEndpoint> 
    <standardEndpoint 
     automaticFormatSelectionEnabled="true" 
     helpEnabled="true" /> 
    </webHttpEndpoint> 
</standardEndpoints> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false"/> 
</system.serviceModel> 
<system.webServer> 
<modules runAllManagedModulesForAllRequests="true"/> 
</system.webServer> 

답변

1

설정 파일에는 몇 가지 사항이 있습니다.

먼저 클라이언트 구성에 <services> 섹션이 있습니다. 클라이언트가 서비스를 호스팅하지 않는 한 거기에는 필요하지 않습니다. 또한 <services> 섹션에서 wsHttpBinding을 사용하고 있지만 클라이언트가 basicHttpBinding을 지정하고 있습니다. 클라이언트와 서비스 바인딩이 일치해야합니다.

둘째로 클라이언트 측 바인딩의 값을 높게 설정했지만 클라이언트 측 바인딩 구성은 서버 측에 아무런 영향을 미치지 않습니다. 서비스 구성에 명시 적 엔드 포인트가 정의되어 있지 않으므로, 기본 Y 인딩 값 (basicHttpBinding)을 갖는 기본 엔드 포인트를 얻게됩니다.

이 같은합니다 (name 속성을 생략하여) 서비스 설정에 basicHttpBinding에 대한 기본 구성을 추가 할 수 있습니다 :

<bindings> 
    <basicHttpBinding>   
    <binding closeTimeout="01:01:00" 
      openTimeout="01:01:00" receiveTimeout="01:10:00" sendTimeout="01:01:00" 
      allowCookies="false" bypassProxyOnLocal="false" 
      hostNameComparisonMode="StrongWildcard" 
      maxBufferSize="2147483647" maxBufferPoolSize="2147483647" 
      maxReceivedMessageSize="2147483647" 
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
      useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
        maxArrayLength="2147483647" 
        maxBytesPerRead="4096" maxNameTableCharCount="2147483647" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" 
        realm="" /> 
     <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

이것은 당신의 client.config에서 동일한 정의 뺀 name 속성입니다. (또한 전송 및 메시지 보안이 정의되었지만 보안 모드가 "none"으로 설정된 이유는 무엇입니까?).

또 다른 옵션은 서비스 구성에 끝점을 명시 적으로 정의하고 사용할 바인딩 구성을 지정하는 것입니다. 클라이언트 설정 파일에서했던 것과 비슷합니다. "BasicHttpBinding_IService"라는 이름의 basicHttpBinding이 있다고 가정 해 보겠습니다. 종점은 다음과 같이 보일 것입니다 :

<services>  
    <service name="LocalService.Service" behaviorConfiguration="ServiceBehavior"> 
    <endpoint address="http://localhost:20314/Service.svc" 
       binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_IService" 
       contract="LocalService.IService" /> 
    </service> 
</services> 
+0

내 시간을 저장했습니다. –

+0

동일한 오류가 발생했기 때문에 서비스 구성 측에서 서비스를 추가하는 대신 첫 번째 방법을 취소했습니다. –

+0

첫 번째 접근 덕분에 어떻게 작동했는지 알 수있었습니다. –