VB.NET的解决方案-“;“WCF服务默认项目设置示例不起作用”;
我知道以前有人问过这个问题,我已经仔细研究了这里仅有的两个问题,很多小时后,我尝试了所有可能的解决方案,我仍然无法让默认的WCF项目在VS2012上运行(请参阅标题中的错误) 简言之: 我只想让默认的WCF应用程序项目在VisualStudio 2012 Pro中工作 我所尝试的: 更改WEB.CONFIG结尾以添加以下内容(这显然对大多数人有效,但对我无效)VB.NET的解决方案-“;“WCF服务默认项目设置示例不起作用”;,vb.net,wcf,web-services,visual-studio-2012,Vb.net,Wcf,Web Services,Visual Studio 2012,我知道以前有人问过这个问题,我已经仔细研究了这里仅有的两个问题,很多小时后,我尝试了所有可能的解决方案,我仍然无法让默认的WCF项目在VS2012上运行(请参阅标题中的错误) 简言之: 我只想让默认的WCF应用程序项目在VisualStudio 2012 Pro中工作 我所尝试的: 更改WEB.CONFIG结尾以添加以下内容(这显然对大多数人有效,但对我无效) 以及以下各项: <behaviors> <serviceBehaviors> <behavi
以及以下各项:
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
iService1.vb代码(未更改默认值):
公共接口IService1
函数GetData(ByVal值为整数)为字符串
函数GetDataUsingDataContract(ByVal composite作为CompositeType)作为CompositeType
'TODO:在此处添加服务操作
端接口
公共类复合类型
公共属性BoolValue()为布尔值
公共属性StringValue()作为字符串
末级
Service1.svc的标记:
<%@ ServiceHost Language="VB" Debug="true" Service="WcfService1.Service1" CodeBehind="Service1.svc.vb" %>
顺便说一句,它有一条蓝色的长曲线,表示“无法识别的配置节服务。(E:\projects\TestJquery\WcfService1\web.config第35行)”,所以我需要其他东西-另一个项目参考
这是完整的web.config文件(唯一改变的是建议添加“服务”部分)
我想,如果我能让默认的WCFWebService项目正常工作,我就能更好地剖析和理解正在发生的事情。如果有人这样做过,请发送一个工作正常的默认VS2012解决方案的zip文件(或链接)。我真的想远离ASMXWeb服务,WCF的词汇似乎没有任何意义
web.config更改-仍然没有工作,但没有蓝色曲线:)
默认、现成的VS2012 WCF WEB服务应用程序工作所需的最终WEB.CONFIG设置。我希望这能帮助所有像我这样的新手在学习WCF时至少有一些东西可以调整:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="metadataBehavior" name="WcfService1.Service1">
<endpoint
address=""
binding= "basicHttpBinding"
contract="WcfService1.IService1"
/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
<add binding="basicHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
好的,有很多事情。正如我在评论中所说的,项目应该在不进行任何更改的情况下正常工作 您发布的代码中的主要问题是web.config不正确-您在
部分之外有
和
部分,这就是您看到错误的原因。此外,您行为的结束标记顺序错误
您的配置应该是这样的:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyServiceBinding" />
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="metadataBehavior" name="WcfService1.Service1">
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="MyServiceBinding"
contract="WcfService1.IService1"/>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
对于初学者。您的服务端点引用了web.config-jsonpBinding
中不存在的绑定配置。您需要在配置中定义该绑定(在
部分。此外,您的
和
部分位于
部分之下,而不是在它之外。2012年的默认项目应该是开箱即用的,绝对没有任何变化。我还建议您在谷歌上搜索WCF服务教程,而不是试图通过反向工程现有的专业软件来解决它。)WCF可以有一个陡峭的学习曲线(尽管在我看来,一旦你学会了它,它就相当直截了当了)。获取属性名称无效,在将其放置到正确位置后,还会出现一些错误。还有更多错误,请稍候。您之所以会遇到这些错误,是因为标记位于配置文件的错误部分。使用WCF 4.0及更高版本,实际上可以在配置文件中不包含任何内容的情况下承载服务。我不同意MSDN是无用的,但是每个人都有自己的一个。而且…?你给我的是没有上下文的代码片段。如果你根本没有
部分,你在上面的代码中所拥有的正是你将得到的。一个默认端点,带有http
-basicHttpBinding
的默认绑定服务名称必须包含根命名空间(本例中为项目名称)-使其为“WcfService1.Service1”。绑定(对于http,不是自定义的)应设置为“basicHttpBinding”。我在合同中犯了一个错误-在VS2012中使用的地址为空(Cassini将根据MSDN为您解决此问题)。契约也是根命名空间,上面点缀着接口名-WcfService1.IService1(注意默认命名包括字母I-表示接口),我知道所有这些:)我的意思是,对于更改,它仍然不起作用吗?您是否收到任何错误消息?它现在起作用。-将设置放置在web.config中是一个良好的开端,而将正确的服务名称和合同放在一起是另一个罪魁祸首。谢谢!
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
<services>
<service behaviorConfiguration="metadataBehavior" name="Service1">
<endpoint
address=""
binding="customBinding" bindingConfiguration="jsonpBinding"
contract="Service1.IService1"/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</configuration>
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="metadataBehavior" name="WcfService1.Service1">
<endpoint
address=""
binding= "basicHttpBinding"
/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="metadataBehavior" name="WcfService1.Service1">
<endpoint
address=""
binding= "basicHttpBinding"
contract="WcfService1.IService1"
/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
<add binding="basicHttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MyServiceBinding" />
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="metadataBehavior" name="WcfService1.Service1">
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="MyServiceBinding"
contract="WcfService1.IService1"/>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>