我打电话给我使用Ajax的wcf服务,为此我配置了我的web.config
文件。但现在当我运行我的服务时,它会发出这样的错误。服务元数据可能无法访问在WCF
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
这是我Interface
namespace WcfWithJson
{
[ServiceContract]
public interface IMyservice
{
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
UserDetails[] GetUserDetails(string Username);
}
}
注:为userDetails是我的类名。 现在我已经实现了我的界面这里
namespace WcfWithJson
{
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService : IMyservice
{
public UserDetails[] GetUserDetails(string Username)
{
string strConnection = ConfigurationManager.ConnectionStrings["MyDbEntities"].ConnectionString;
List<UserDetails> userdetails = new List<UserDetails>();
using (SqlConnection con = new SqlConnection(strConnection))
{
// some sql Code here
}
return userdetails.ToArray();
}
}
}
,这是我web.config
文件
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="WcfWithJson.MyService" behaviorConfiguration="metadataBehavior">
<endpoint address="" binding="basicHttpBinding" contract="WcfWithJson.IMyservice" behaviorConfiguration="EndPointBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="EndPointBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
这是完全错误:
Error: Cannot obtain Metadata from http://localhost:61762/MyService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.
For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:61762/MyService.svc Metadata contains a reference that cannot be resolved: 'http://localhost:61762/MyService.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:61762/MyService.svc. The client and service bindings may be mismatched. The remote server returned an error: (415) Unsupported Media Type.HTTP GET Error URI: http://localhost:61762/MyService.svc The HTML document does not contain Web service discovery information.
尝试为元数据添加额外的端点。 –
jadavparesh06
2014-10-09 05:19:47
@ jadavparesh06:我加了这个,但是仍然有同样的问题 – 2014-10-09 05:33:19