代码之家  ›  专栏  ›  技术社区  ›  capdragon

在jQuery客户端和wcfsoapweb服务之间“404notfound”

  •  0
  • capdragon  · 技术社区  · 14 年前

    有人能发现我的代码有什么问题吗?当我使用jQuery调用wcfsoap服务时,在firebug上找不到404。

    我在用IIS7玩Win7。我在虚拟目录应用程序上运行wcf( http://localhost/csw ). 我可以访问服务.svc此url中没有问题的文件:( http://localhost/csw/service.svc

    这是我的Web.config文件在配置标签之间

    <configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0"/>
    </system.web>
    <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name ="soapBinding">
          <security mode="None">
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        <services>
            <service name="CatalogService" behaviorConfiguration="defaultBehavior">  
        <endpoint address="soap"
                  binding="basicHttpBinding"
                  bindingConfiguration="soapBinding"
                  contract="ICatalogService" />
            </service>
        </services>
        <behaviors>
            <endpointBehaviors>
                <behavior name="xmlBehavior">
                    <webHttp/>
                </behavior>
            </endpointBehaviors>
            <serviceBehaviors>    
                <behavior name="defaultBehavior">
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="true"/>
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
    

    应用程序代码/ICatalogServices.cs公司:

    [ServiceContract(Namespace = "http://test/CatalogService")] public interface ICatalogService {
    [WebInvoke(Method = "POST",
                 BodyStyle = WebMessageBodyStyle.Wrapped,
                 ResponseFormat = WebMessageFormat.Xml,
                 RequestFormat = WebMessageFormat.Xml)]
    string HelloWorld(string name);}
    

    应用程序代码/目录服务.cs:

    public class CatalogService : ICatalogService{
    public string HelloWorld(string name){
        return String.Format("Hello {0}", name);}}
    

        $.ajax({
        type: 'POST',
        url: 'http://localhost/csw/service.svc/HelloWorld',
        data: request,
        contentType: 'application/xml; charset=utf-8',
        dataType: 'xml',
        success: function (result) {
            console.log(result);
    
            $("#result").text(result);
            //result.responseXML
            //result.responseText
        },
        error: function (message) {
            console.log(message);
            alert("error has occured" + message);
        }
    });
    

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">  <s:Body>  <HelloWorld xmlns="http://test/CatalogService">  <name>CarlosK</name>  </HelloWorld>  </s:Body>  </s:Envelope>
    
    1 回复  |  直到 14 年前
        1
  •  3
  •   Ladislav Mrnka    14 年前

    jQuery代码中的URL错误。尝试使用 http://localhost/csw/service.svc/soap . 同时将内容类型更改为text/xml;charset=utf-8

    地址:调用SOAP服务时,操作名称不是URL的一部分。(与休息服务相反)。在您的配置中,还定义了SOAP端点的相对地址。有效的URL是BaseAddress+/服务.svc+/相对地址。基于的地址由虚拟目录定义。

    编辑新错误:

    新错误表示它无法将空操作路由到服务中的操作。您必须将SOAPAction HTTP头添加到jQuery生成的请求中。标头的值应为 http://test/CatalogService/ICatalogService/HelloWorld