我有一个WCF应用程序作为Azure中的webrole托管,具有以下配置。在尝试访问浏览器中的三个服务wsdl中的任何一个或尝试设置代理时,我收到400 Bad Request。
<?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>
我很确定我的配置不对,但我需要一些不正确的指导。
接口定义为:
[ServiceContract(Name = "Service1", Namespace = "http://example.com")]
public interface IService1
{
[WebGet]
[OperationContract]
Result Create();
}
答案 0 :(得分:3)
您使用的是错误的绑定,请尝试使用webHttpBinding而不是basicHttpBinding。您的合同设置为WebGet,这是WCF对基于REST的服务的承担。 BasicHttpBinding仅适用于基于soap的绑定(因此“错误请求”异常)。
编辑:
由于WebGet
存在,我认为你不想要肥皂终点。下面是一个支持soap和WebGet的配置。我不知道Azure与标准IIS的不同之处,但您应该使用相对地址来进行服务。 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>