[英]Is this WCF configuration causing my 400 bad request?
I have a WCF application hosted as a webrole in Azure with the following configuration. 我将WCF应用程序托管为Azure,具有以下配置。 I am getting a 400 Bad Request when trying to access any of the three service wsdl in a browser or when trying to set up a proxy.
尝试访问浏览器中的三个服务wsdl中的任何一个或尝试设置代理时,收到400错误请求。
<?xml version="1.0"?>
<configuration>
<appSettings>
</appSettings>
<system.web>
<customErrors mode="Off"></customErrors>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings></connectionStrings>
<system.diagnostics>
<sharedListeners>
<add name="AzureLocalStorage" type="Example.AzureLocalStorageTraceListener, Example"/>
</sharedListeners>
<sources>
<source name="System.ServiceModel" switchValue="Verbose, ActivityTracing">
<listeners>
<add name="AzureLocalStorage" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
<listeners>
<add name="AzureLocalStorage" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.serviceModel>
<services>
<service name="Service1" behaviorConfiguration="MetaBehavior">
<endpoint address="http://example.com/service1.svc" binding="basicHttpBinding" name="basicEndpoint1" contract="IService1" />
</service>
<service name="Service2" behaviorConfiguration="MetaBehavior">
<endpoint address="http://example.com/service2.svc" binding="basicHttpBinding" name="basicEndpoint2" contract="IService2" />
</service>
<service name="Service3" behaviorConfiguration="MetaBehavior">
<endpoint address="http://pexample.com/service3.svc" binding="basicHttpBinding" name="basicEndpoint3" contract="IService3" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetaBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true"/>
<serviceThrottling maxConcurrentSessions="90" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
I am pretty sure my configuration is not right but I need a little guidance with what is incorrect. 我很确定我的配置不正确,但是我需要一些不正确的指导。
An interface is defined as: 接口定义为:
[ServiceContract(Name = "Service1", Namespace = "http://example.com")]
public interface IService1
{
[WebGet]
[OperationContract]
Result Create();
}
You're using the wrong binding, try webHttpBinding instead of basicHttpBinding. 您使用了错误的绑定,请尝试使用webHttpBinding而不是basicHttpBinding。 Your contract is set to WebGet which is WCF's take on a quasi-REST based service.
您的合同设置为WebGet,这是WCF采取的基于REST的服务。 BasicHttpBinding is only for soap based bindings (hence the "Bad request" exception).
BasicHttpBinding仅适用于基于肥皂的绑定(因此会出现“错误请求”异常)。
EDIT: Since the WebGet
was present, I assumed you didn't want soap endpoints. 编辑:自从
WebGet
存在以来,我以为您不想要soap端点。 Below is a config that supports both soap and WebGet. 下面是同时支持soap和WebGet的配置。 I don't know how different Azure is from standard IIS but you should probably use relative addresses for your service.
我不知道Azure与标准IIS有何不同,但是您应该为服务使用相对地址。 IIS will only support relative addresses in the service config.
IIS将仅在服务配置中支持相对地址。
<system.serviceModel>
<services>
<service name="Service1" behaviorConfiguration="Service.Behavior">
<endpoint address="Service1"
binding="basicHttpBinding"
contract="IService1"
bindingNamespace = "http://example.com"
bindingConfiguration="HttpBasic" />
<endpoint address="mexService1"
binding="mexHttpBinding"
contract="IMetadataExchange"
bindingNamespace = "http://example.com"/>
<endpoint address="webService1"
binding="webHttpBinding"
behaviorConfiguration="webBehavior"
contract="IService1"
bindingNamespace = "http://example.com"
name="webHttp"
listenUriMode="Explicit" />
</service>
<service name="Service2" behaviorConfiguration="Service.Behavior">
<endpoint address="Service2"
binding="wsHttpBinding"
contract="IService2"
bindingNamespace = "http://example.com"
bindingConfiguration="HttpStandard" />
<endpoint address="mexService2"
binding="mexHttpBinding"
contract="IMetadataExchange"
bindingNamespace = "http://example.com"/>
<endpoint address="webService2"
binding="webHttpBinding"
behaviorConfiguration="webBehavior"
contract="IService2"
bindingNamespace = "http://example.com"
name="webHttp"
listenUriMode="Explicit" />
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior" >
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Service.Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="HttpBasic" receiveTimeout="00:10:00" maxReceivedMessageSize="2048000">
<security mode="None"/>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="HttpStandard" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2048000">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="None" negotiateServiceCredential="false" algorithmSuite="Default" establishSecurityContext="false" />
</security>
</binding>
<binding name="Https" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2048000">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="None" negotiateServiceCredential="false" algorithmSuite="Default" establishSecurityContext="false" />
</security>
</binding>
<binding name="HttpsAuthenticated" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2048000">
<security mode="Transport">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.