当我添加新项目(wcf服务)时,在运行服务后发生错误

时间:2011-12-25 21:17:02

标签: wcf

我有一个Wcf服务,可以正常使用Service1,这是默认的。我通过网址localhost:1234/Service2.svc/myMethod2/comeOn

找到了它

如果我添加另一个服务文件(通过在VS 2010中添加新项目选项),当我想在其中调用方法时:

localhost:1234/MyWebServices.svc/myMethod/comeOn

它没有用。

它说'资源无法找到'。我的网址中的路径是正确的。为什么会这样?

这是我的web.config文件:

<?xml version="1.0"?>
<configuration>
  <appSettings />
  <connectionStrings>
  something
  </connectionStrings>
  <system.web>
     <compilation debug="true">
       <assemblies>
          <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
       </assemblies>
     </compilation>
     <authentication mode="Windows" />
     <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
  </system.web>
  <system.serviceModel>
    <services>
       <service behaviorConfiguration="MyWebServices.GetFromEmployeeBehavior" name="MyWebServices.GetFromEmployee">
           <endpoint address="json" behaviorConfiguration="poxBehavior" 
                     binding="webHttpBinding" 
                     contract="MyWebServices.IGetFromEmployee" />
           <endpoint address="mex" 
                     binding="mexHttpBinding" contract="IMetadataExchange" />
       </service>
    </services>
    <behaviors>
       <endpointBehaviors>
          <behavior name="msAjaxBehavior">
             <enableWebScript />
          </behavior>
          <behavior name="poxBehavior">
             <webHttp />
          </behavior>
       </endpointBehaviors>
       <serviceBehaviors>
          <behavior name="MyWebServices.GetFromEmployeeBehavior">
            <serviceMetadata httpGetEnabled="true" httpGetUrl="" />
            <serviceDebug httpHelpPageEnabled="true" 
                          includeExceptionDetailInFaults="true" />
          </behavior>
       </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

这是我的.svc.cs文件:

public class GetFromEmployee : IGetFromEmployee
{
    public MyClass myMethod(string input)
    {
        MyClass newMyClass  = new Pong();
        newMyClass.ping = input;
        return novPong;
    }
}

这是我的合同文件:

[ServiceContract]
public interface IGetFromEmployee
{
    [OperationContract]
    [WebInvoke(Method = "GET", 
               RequestFormat = WebMessageFormat.Json, 
               ResponseFormat = WebMessageFormat.Json, 
               UriTemplate = "/myMethod/{input}", 
               BodyStyle = WebMessageBodyStyle.Bare)]
    MyClass myMethod(string input);
}

0 个答案:

没有答案