1

这应该足够了。如果我去site/core.svc/dowork我得到一个 400 错误。

.ajax 调用的结果相同。我哪里做错了?

我正在努力使这个网络可以访问。我将添加一些方法来处理基于浏览器事件的状态管理。

[ServiceContract]
public interface Icore
{
    [OperationContract]
    [WebGet(ResponseFormat = WebMessageFormat.Xml)]
    string DoWork();
}

[System.Web.Script.Services.ScriptService]
public class core : Icore
{
    public string DoWork()
    {
        return "hello";
    }
}

<behaviors>
  <endpointBehaviors>
    <behavior name="RestBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="MetadataBehavior">
      <serviceMetadata httpsGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<services>
  <!-- Note: the service name must match the configuration name for the service implementation. -->
  <service name="Fusion.core" behaviorConfiguration="MetadataBehavior" >
    <!-- Add the following endpoint.  -->
    <!-- Note: your service must have an http base address to add this endpoint. -->
    <endpoint contract="Fusion.Icore" binding="wsHttpBinding" bindingConfiguration="HttpsBinding" address="" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

<bindings>
  <basicHttpBinding>
    <binding name="secureBinding">
      <security mode="Transport"/>
    </binding>
  </basicHttpBinding>
  <wsHttpBinding>
    <binding name="HttpsBinding">
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
4

1 回答 1

2

在这种情况下,想要使您的服务Web 可访问(可从常规浏览器调用),您需要使用 REST 方法(而不是 SOAP)。

为此,您使用了错误的绑定;您需要使用webHttpBinding(而不是wsHttpBindingor basicHttpBinding,它们是不能从浏览器调用的 SOAP 绑定 - 您需要一个 SOAP 客户端软件)

于 2012-12-21T19:04:05.513 回答