C# 无法在web.config中为WCF web服务设置服务名称属性
我编写了一个WCF web服务,它运行良好,然后我从另一个应用程序复制了web服务的内容,并创建了一个新的WCF文件,该文件在web.config中创建了一个新的名称,但name属性表示找不到名称空间 以下是我的WCF的前几行的示例:C# 无法在web.config中为WCF web服务设置服务名称属性,c#,wcf,C#,Wcf,我编写了一个WCF web服务,它运行良好,然后我从另一个应用程序复制了web服务的内容,并创建了一个新的WCF文件,该文件在web.config中创建了一个新的名称,但name属性表示找不到名称空间 以下是我的WCF的前几行的示例: namespace Testing.ws.mainGrid { [WebService(Namespace = "")] [ScriptService] [ToolboxItem(false)] [WebServiceBinding
namespace Testing.ws.mainGrid
{
[WebService(Namespace = "")]
[ScriptService]
[ToolboxItem(false)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Test : WebService
{
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
[WebMethod]
public void GetRecords()
{
((NameValueCollection)new WebClient().Headers).Add("accept", "text/xml");
string str1 = "1";
string str2 = "1";
string str3 = "1";
这是我的web.config:
<system.serviceModel>
<services>
<service name="Testing.ws.getStaffTree">
<endpoint address="" behaviorConfiguration="Testing.ws.getStaffTreeAspNetAjaxBehavior"
binding="webHttpBinding" contract="Testing.ws.getStaffTree" />
</service>
<service name="Testing.ws.mainGrid.Test">
<endpoint address="" behaviorConfiguration="Testing.ws.mainGridAspNetAjaxBehavior"
binding="webHttpBinding" contract="Testing.ws.mainGrid" />
</service>
</services>
基本上,name=“Testing.ws.mainGrid.Test”
不起作用,也找不到它
我不确定我做错了什么,但我已经花了很多时间在这上面了!第一个很好,但这是第二个问题
实际误差为:
“name”属性无效-根据其数据类型“serviceNameType”,Testing.ws.mainGrid.Test值无效-枚举约束失败
如果您让intellisense完成它的工作,那么它将显示第一个web服务,而不是我的新服务 我认为您的第二次服务应该如下所示。注意合同名称的变更:
<service name="Testing.ws.mainGrid.Test">
<endpoint address="" behaviorConfiguration="Testing.ws.mainGridAspNetAjaxBehavior"
binding="webHttpBinding" contract="Testing.ws.mainGrid.Test" />
</service>
在它指向名称空间之前,而不是类类型。虽然我们遇到了相同的问题,但由于我们的开发环境对某些服务使用windows身份验证,同时通过web.config专门禁用了它,因此我们的修复略有不同 需要注释掉/删除web.config的以下部分
<system.webServer>
<!--<security>
<authentication>
<windowsAuthentication enabled="false" />
</authentication>
</security>-->
</system.webServer>
这需要取消注释,以便发布到生产环境中是唯一的事情。看起来您将ASMX(您的类实现)与WCF(您的web.config)混合在一起。此外,您尝试将
webHttpBinding
用于SOAP服务-webHttpBinding
用于REST。