在這裏,當我想發送字節數組它給我錯誤的請求錯誤。我已經檢查了所有消息限制的最大值。所有都設置爲最大值。 但是我能夠通過將字節數組參數保留爲空來將字符串值發送到service方法。我不知道爲什麼發生在這裏。我還檢查了服務行爲配置名稱和綁定配置名稱(即包含的名稱空間),這似乎很好。任何幫助都非常感謝。傳遞字節數組到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);
}
}
}
.......
客戶端的web配置:
<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>
服務Web配置
<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>
你救了我的時間 –
我abopted第一種方法,而不是在服務配置方面增加服務,因爲它給我同樣的錯誤。 –
任何感謝你的第一種方法,它工作得很好。 –