【发布时间】:2014-01-01 06:52:22
【问题描述】:
在这里,当我尝试发送字节数组时,它给了我错误的请求错误。我已经检查了所有消息限制的最大值。全部设置为最大值。 但是,我可以通过将字节数组参数保持为空来将字符串值发送到服务方法。我不知道为什么会在这里发生。我还检查了服务行为配置名称和绑定配置名称(即包含的命名空间),这似乎很好。非常感谢任何帮助。
这是我的客户端代码:
....
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>
【问题讨论】:
标签: asp.net-mvc-3 wcf c#-4.0 wcf-binding wcf-security