C# Can';无法将的服务引用从WCF项目添加到WPF客户端,下载元数据时出错
我在将WCF应用程序中的服务引用添加到WPF客户端时遇到问题 在四个项目中,有两个是WCF应用程序,其中包括一个“WCF服务”,其中包含三个接口合同IService1、IService2和IService3(不同名称的irl), 还有一个WPF项目,它是客户端 当尝试向WPF项目添加服务引用时,它在“添加服务引用”窗口中按“发现”后确实会找到该服务,但一旦按“转到”按钮或“确定”按钮,它就会开始加载,然后给出错误消息。 尝试在“”处查找服务时出错(详细信息(链接)) 在“细节”链接中,它说 “下载“$metadata”时出错。” 但是,当单独启动WCF项目时,它可以完美地加载IIS express 我尝试了许多解决类似问题的方法,但没有一个有效。 我已经试过了: 生成/重新生成解决方案 在web.config中查找错误,但似乎一切正常。 在WCF实例联机时启动WCF项目并尝试添加服务引用。 在以管理员身份运行VS时尝试以上所有操作。 还有更多我想不起来的 这里有一些代码和错误信息,也许我遗漏了什么 代码: WCF服务:C# Can';无法将的服务引用从WCF项目添加到WPF客户端,下载元数据时出错,c#,wpf,wcf,service-reference,C#,Wpf,Wcf,Service Reference,我在将WCF应用程序中的服务引用添加到WPF客户端时遇到问题 在四个项目中,有两个是WCF应用程序,其中包括一个“WCF服务”,其中包含三个接口合同IService1、IService2和IService3(不同名称的irl), 还有一个WPF项目,它是客户端 当尝试向WPF项目添加服务引用时,它在“添加服务引用”窗口中按“发现”后确实会找到该服务,但一旦按“转到”按钮或“确定”按钮,它就会开始加载,然后给出错误消息。 尝试在“”处查找服务时出错(详细信息(链接)) 在“细节”链接中,它说 “下
using Common.Models;
using WCFChatAndPlay.ServiceInterfaces;
using DAL.DbOperations;
using System.Collections.Generic;
using Common.Enums;
using System.ServiceModel;
namespace WCFChatAndPlay.Services
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class PlayAndChatService : IUserService, IGameService, IChatService
{
#region IUserService
public bool AddUser(UserModel newUser)
{
//Adding user to Db
}
public List<UserModel> GetOnlineUsers(UserModel currentUser)
{
//Gets all online users
}
public UserModel GetUser(UserModel requestedUser)
{
//Getting a specific user
}
#endregion
#region IGameService
public void MovePiece(PlayerModel p, GameCellModel source, GameCellModel destination)
{
//Doing some game operations
}
public void StartGame(GameModel game)
{
//Init Game
}
#endregion
#region IChatService
public void SendMessage(string message)
{
//Send Message
}
public void SendInvite(UserModel targetUser)
{
//Send Invite
}
#endregion
}
}
服务2:
using Common.Models;
using System.ServiceModel;
namespace WCFChatAndPlay.ServiceInterfaces
{
[ServiceContract]
interface IGameService
{
[OperationContract]
void StartGame(GameModel game);
[OperationContract]
void MovePiece(PlayerModel p, GameCellModel source, GameCellModel destination);
[OperationContract]
void EatPiece();
}
}
服务3:
using Common.Models;
using System.Collections.Generic;
using System.ServiceModel;
namespace WCFChatAndPlay.ServiceInterfaces
{
[ServiceContract]
public interface IUserService
{
[OperationContract]
bool AddUser(UserModel newUser);
[OperationContract]
UserModel GetUser(UserModel requestedUser);
[OperationContract]
List<UserModel> GetOnlineUsers(UserModel currentUser);
}
}
使用通用的.Models;
使用System.Collections.Generic;
使用System.ServiceModel;
命名空间WCFChatAndPlay.ServiceInterfaces
{
[服务合同]
公共接口服务
{
[经营合同]
bool AddUser(UserModel newUser);
[经营合同]
UserModel GetUser(UserModel requestedUser);
[经营合同]
列出GetOnlineUsers(UserModel currentUser);
}
}
web.Config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<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"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
您一直在说“将WCF项目中的服务引用添加到WPF客户端”。这不是倒退吗?你不想要一个指向WCF项目的WPF项目的服务参考吗?正是我的意思,也许我没有像我应该解释的那样解释它,但我会尽力按照你说的做
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<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"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>