我已经从我的一个用户那里得到了WCF服务。我想检查服务是否正常工作而不添加任何代理。有什么方法可以在我的C#代码中实现这一点?WCF服务没有在C#中使用代理服务器
1
A
回答
0
您可以通过在WCF上实现端点并从客户端查询它来实现此目的。 以下是我将使用的WCF代码。
// Used for communication between WCF and client. Must be implemented both WCF and client sides
public class Response {
public int Id { get; set; }
public string Data { get; set; }
}
// Web Service - Interface
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
UriTemplate = "Up")]
string CheckLogin();
}
// Web service - Implementation
public class ServiceImplementation : IService
{
public Response isUp()
{
Response response = new Response();
response.ID = 200;
response.Data = "web service is up";
return response;
}
}
以下是测试服务是否启动的客户端方法。
public bool CheckIfUp(string encodedUrl)
{
WebRequest request;
WebResponse ws;
Response response = new Response();
string url = "http://servicePath/isUp"; // your wcf url
try
{
request = WebRequest.Create(url);
ws = request.GetResponse();
return (response.ID == 200);
}
catch (Exception e)
{
Console.Write(e.StackTrace);
}
return false;
}
希望这会有所帮助。
+0
我无权访问WCF服务代码。我只有服务网址。 –
0
尝试在指向WCF服务的URL处追加?wsdl
。
如果您的Web服务地址是
http://services.aonaware.com/DictService/DictService.asmx
你可以这样达到您的WSDL文件:
http://services.aonaware.com/DictService/DictService.asmx?WSDL
返回的WSDL,您可以看到所有的WCF服务提供的方法。
相关问题
- 1. 正确使用C#中的工厂和服务代理处理WCF服务
- 2. 2.0 Web服务代理WCF服务
- 3. 使用jQuery使用WCF服务代理
- 4. WCF代理调用没有注册到服务器?
- 5. Grunt Connect代理服务器没有连接到代理服务器
- 6. RESTful WCF服务代理
- 7. Azure WCF服务使用Azure WCF服务
- 8. 通过服务器/代理服务器
- 9. 在初始化/代理服务器/代理服务器/
- 10. 使用WCF代理将服务引用(WCF,VS2008)添加到外部服务
- 11. 拥有WCF服务代理可配置
- 12. 如何在C#中使用WCF服务
- 13. 通信web-windows服务器:代理DLL,web服务或windows服务+ WCF?
- 14. 在没有服务引用的情况下调用WCF服务
- 15. WCF服务没有响应
- 16. 有没有人使用YAWS服务器作为HTTP代理?
- 17. 从WCF服务提供JSON服务在IIS中没有扩展
- 18. Web服务和代理服务器
- 19. 使用TFS代理服务器作为脱机TFS服务器
- 20. 使用代理服务器隧道移动web服务器
- 21. c中的Internet代理服务器#
- 22. C#插座:通过代理服务器连接到服务器
- 23. WCF数据服务 - 代理中间服务
- 24. 代理服务器在php
- 25. 在node.js中调用https web服务(代理服务器后台)
- 26. WCF服务管理
- 27. httlib和HTTPSConnection问题使用代理服务器(代理服务器)
- 28. WCF:服务调用服务
- 29. 服务在WCF服务
- 30. SQL服务器:链接服务器没有链接服务器?
使用ChannelFactory。您将需要访问服务程序集来执行此操作。 –