Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中不使用代理的WCF服务#_C#_Wcf - Fatal编程技术网

C# 在C中不使用代理的WCF服务#

C# 在C中不使用代理的WCF服务#,c#,wcf,C#,Wcf,我从我的一个用户那里得到了WCF服务。我想在不添加任何代理的情况下检查服务是否正常工作。有什么方法可以在我的C#代码中实现这一点吗?您可以通过在WCF实现端点并从客户端查询来实现这一点。 下面是我将使用的WCF代码 // Used for communication between WCF and client. Must be implemented both WCF and client sides public class Response { public int Id { get;

我从我的一个用户那里得到了WCF服务。我想在不添加任何代理的情况下检查服务是否正常工作。有什么方法可以在我的C#代码中实现这一点吗?

您可以通过在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;
 }

希望这有帮助。

您可以通过在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;
 }

希望这有帮助。

尝试在指向WCF服务的URL的末尾添加
?wsdl

如果您的Web服务地址为

http://services.aonaware.com/DictService/DictService.asmx
您可以通过以下方式访问wsdl文件:

http://services.aonaware.com/DictService/DictService.asmx?WSDL

返回的WSDL允许您查看WCF服务提供的所有方法。

请尝试在指向WCF服务的URL的末尾追加
?WSDL

如果您的Web服务地址为

http://services.aonaware.com/DictService/DictService.asmx
您可以通过以下方式访问wsdl文件:

http://services.aonaware.com/DictService/DictService.asmx?WSDL

返回的WSDL允许您查看WCF服务提供的所有方法。

使用ChannelFactory。您需要访问服务程序集才能执行此操作。请使用ChannelFactory。您需要访问服务程序集才能执行此操作。我无权访问WCF服务代码。我只有服务url。我没有访问WCF服务代码的权限。我只得到了服务url。