简体   繁体   English

使简单的WCF服务正常工作的问题

[英]Issues getting simple WCF service working

I am having a frustrating time getting both POST and GET running on my webservice. 我在Web服务上同时运行POST和GET时感到沮丧。 I need to stop, chill out and figure out what is going wrong. 我需要停下来,放松一下,找出问题所在。

I broke it down to a very simple method that just takes a string and echos it back. 我将其分解为一个非常简单的方法,该方法只需要一个字符串并将其回显。 This works on the IIS I have set on my localhost, it works on the production box, but the same configuration is breaking on my test system. 这可以在我在本地主机上设置的IIS上使用,也可以在生产盒上使用,但是相同的配置在我的测试系统上中断了。 Please let me know what I am doing wrong. 请让我知道我在做什么错。 When accessing: 访问时:

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

I am getting a page with a bold header with the text "Service" and the sub header in smaller text stating "Endpoint not found.". 我正在获取一个页面,该页面的标题为粗体,文本为“ Service”,子标题为较小的文本,表明“ Endpoint not found”。 Why am I getting this message? 为什么收到此消息? The same service works on my local host using the query string "http://localhost/Services/WebPostSvc.svc/json/Test?testtext=test%20me". 使用查询字符串“ http://localhost/Services/WebPostSvc.svc/json/Test?testtext = test%20me”在我的本地主机上可以使用相同的服务。 and I'm getting the response: 我得到回应:

<string>Echoing test me</string>

The production server, which I can't put a link to, since it is internal is giving a slightly different response, but it's still working fine: 我无法链接到生产服务器,因为它是内部的,给出的响应略有不同,但是仍然可以正常工作:

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

It is frustrating when I publish locally, hit the local web server, everything is working. 当我在本地发布,在本地Web服务器上运行时,一切都令人沮丧。 I copy the published folder to the production server, type in the similar URL on that server, everything is working, then I ftp the same code, and the same settings to my test server, and it is breaking with the error listed above (Endpoint not found.). 我将发布的文件夹复制到生产服务器,在该服务器上键入类似的URL,一切正常,然后将相同的代码和相同的设置ftp到我的测试服务器ftp,并且由于上面列出的错误而中断(端点未找到。)。 What am I not understanding that is keeping me from getting a simple service to run on the test server? 我不明白是什么让我无法在测试服务器上运行简单的服务?

The Interface for the web service: Web服务的接口:

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

This is the simple method I am trying to get working: 这是我尝试使用的简单方法:

    [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);
        }
    }

My settings are getting unweildy, as I have been fiddling with them trying to get everything working. 我的设置变得越来越古怪,因为我一直在摆弄它们,以使一切正常。 UPDATE - I just removed the serviceHostingEnvironment section, it didn't seem to be necessary, Web Service is still up and working with SOAP, but json is still giving me "Endpoint not found". 更新-我刚刚删除了serviceHostingEnvironment部分,似乎没有必要,Web Service仍在运行并且可以使用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>

Your service does not have any host defined in the endpoints. 您的服务在端点中没有定义任何主机。

 <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>

Try to add UriTemplate to WebGet. 尝试将UriTemplate添加到WebGet。 Actually you should use WebInvoke for POST. 实际上,您应该将WebInvoke用于POST。

Thank you, those that answered so quickly. 谢谢那些回答如此迅速的人。 I found my particular issue, it wasn't in the configuration as I had thought. 我发现了我的特定问题,它不在我想象的范围内。

The server I was publishing to did not have .NET 3.5 installed, which is fine, because .NET 2.0 will suffice, but it was missing assemblies. 我要发布的服务器没有安装.NET 3.5,这很好,因为.NET 2.0足够了,但是缺少程序集。 I don't know why I didn't get a better error message, but the solution was to look through my references, and switch them to "Copy Local" and do a republish, after which everything was working on that server. 我不知道为什么我没有收到更好的错误消息,但是解决方案是浏览我的引用,然后将它们切换到“复制本地”并进行重新发布,之后所有工作都在该服务器上进行。 I did the "Copy Local" on all the references out of frustration, but I'm sure I only needed to do this to the ones that were not included in the .NET 2.0 framework. 我很沮丧地对所有引用进行了“本地复制”,但是我敢肯定,我只需要对.NET 2.0框架中未包含的内容执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM