0

我在我的网络服务上同时运行 POST 和 GET 时遇到了令人沮丧的事情。我需要停下来,冷静下来,找出问题所在。

我把它分解成一个非常简单的方法,它只需要一个字符串并回显它。这适用于我在本地主机上设置的 IIS,它适用于生产机器,但相同的配置在我的测试系统上中断。请让我知道我做错了什么。访问时:

http://test.softwaredesignexcellence.com/WebPostService/WebPostSvc.svc/json/Test?testtext=test%20me

我得到一个带有粗体标题的页面,其中包含文本“服务”和较小文本的子标题,说明“找不到端点。”。为什么我会收到此消息?使用查询字符串“http://localhost/Services/WebPostSvc.svc/json/Test?testtext=test%20me”在我的本地主机上运行相同的服务。我得到了回应:

<string>Echoing test me</string>

生产服务器,我无法链接到,因为它是内部的,它给出的响应略有不同,但它仍然工作正常:

 <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Echoing test me</string>

当我在本地发布,访问本地 Web 服务器时,一切正常,这令人沮丧。我将发布的文件夹复制到生产服务器,在该服务器上输入类似的 URL,一切正常,然后我将相同的代码和相同的设置 ftp 到我的测试服务器,它与上面列出的错误(端点未找到。)。 我不明白是什么让我无法在测试服务器上运行一个简单的服务?

Web服务的接口:

    [ServiceContract( Namespace="http://services.alorica.com/WebPostSvc/1.0" )]
    public interface IWebPostSvc
    {
        [OperationContract]
        [WebGet]
        string Test(string testtext);
    }

这是我试图开始工作的简单方法:

    [WebService(Namespace = "http://services.alorica.com/WebPostSvc/1.0")]
    [ServiceBehavior(Namespace = "http://services.alorica.com/WebPostSvc/1.0")]
    public class WebPostSvc : IWebPostSvc
    {
        public string Test(string testtext)
        {
             return String.Format("Echoing {0}", testtext);
        }
    }

我的设置变得笨拙,因为我一直在摆弄它们以使一切正常。更新 - 我刚刚删除了 serviceHostingEnvironment 部分,它似乎没有必要,Web 服务仍在运行并使用 SOAP,但 json 仍然给我“找不到端点”。

 <system.serviceModel>

    <!-- Set up Custom Behaviors -->
    <behaviors>

      <endpointBehaviors>
        <behavior name="jsonBehavior">
          <webHttp/>

        </behavior>
      </endpointBehaviors>


      <serviceBehaviors>
        <behavior name="SvcMetaBehavior" >
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>

    </behaviors>


    <!-- Set up the binding configuration  -->
    <bindings>

      <basicHttpBinding>
        <binding name="SOAPBinding">
          <security mode="None">

          </security>
        </binding>
      </basicHttpBinding>

      <webHttpBinding>
        <binding name="JSONBinding"
                 hostNameComparisonMode="StrongWildcard"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:10:00"
                 openTimeout="00:10:00"
                 closeTimeout="00:10:00"
                 maxReceivedMessageSize="1000000"
                 maxBufferPoolSize="2000000"
                 bypassProxyOnLocal="false"
                 useDefaultWebProxy="true" >
          <security mode="None">

          </security>
        </binding>
      </webHttpBinding>


    </bindings>

    <services>

      <!-- -->
      <service  behaviorConfiguration="SvcMetaBehavior"
               name="WebPostService.WebPostSvc"
      >

        <endpoint address="soap"
                  binding="basicHttpBinding"
                  bindingConfiguration="SOAPBinding"
                  contract="WebPostService.IWebPostSvc"
        />

        <endpoint address="json"
                  binding="webHttpBinding"
                  bindingConfiguration="JSONBinding"
                  behaviorConfiguration="jsonBehavior"
                  contract="WebPostService.IWebPostSvc"

        />

        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />

      </service>

    </services>

  </system.serviceModel>
4

3 回答 3

1

您的服务没有在端点中定义任何主机。

 <services>
  <service name="WebPostService.WebPostSvc">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="SOAPBinding" name="serviceBasicHttpBinding" contract="WebPostService.IWebPostSvc">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://test.softwaredesignexcellence.com" />
      </baseAddresses>
    </host>
  </service>
     </services>
于 2012-07-03T17:46:04.777 回答
0

尝试将UriTemplate添加到 WebGet。实际上,您应该使用WebInvoke进行 POST。

于 2012-07-03T17:45:57.067 回答
0

谢谢那些这么快回答的人。我发现了我的特殊问题,它不像我想象的那样在配置中。

我发布到的服务器没有安装 .NET 3.5,这很好,因为 .NET 2.0 就足够了,但它缺少程序集。我不知道为什么我没有收到更好的错误消息,但解决方案是查看我的参考资料,并将它们切换到“复制本地”并重新发布,之后一切都在该服务器上运行。出于沮丧,我对所有引用进行了“复制本地”,但我确信我只需要对未包含在 .NET 2.0 框架中的引用执行此操作。

于 2012-07-03T18:55:40.167 回答