简体   繁体   English

WCF服务无法在自身网络中工作

[英]wcf service are not working in self network

I am new to WCF. 我是WCF的新手。 I have a WCF Service application created in VS 2012. 我有一个在VS 2012中创建的WCF服务应用程序。

When I execute it from VS, it runs and shows the service running in the browser. 当我从VS执行它时,它将运行并显示在浏览器中运行的服务。

I now want to create a client to test the service. 我现在想创建一个客户端来测试服务。 How can I do this? 我怎样才能做到这一点?

Service code as follows: 服务代码如下:

public class CallList : ICallList
{
    public String List(String id,String name)
    {            
        String Message;

        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=CallList;Integrated Security=True");//Data Source=ANDROID-PC\SQLEXPRESS;Initial Catalog=CallList;Integrated Security=True
        con.Open();
        SqlCommand cmd = new SqlCommand("insert into CallLog(id,name) values(@id,@name)", con);
        cmd.Parameters.AddWithValue("@id", id);
        cmd.Parameters.AddWithValue("@name", name);

        int result = cmd.ExecuteNonQuery();

        if (result == 1)
        {
            Message =  " Details inserted successfully";
        }
        else
        {
            Message = " Details not inserted successfully";
        }

        con.Close();

        return Message;           
    }
}

Please can someone help me with how to test this service. 请有人可以帮助我测试该服务。

First of all I don't see any service Implementation in your code.but Here is a simple article I wrote while ago. 首先,我在您的代码中看不到任何服务实现。但这是我之前写的一篇简单文章 it contain how to create WCF service and test it using WCF Test client. 它包含如何创建WCF服务以及如何使用WCF测试客户端对其进行测试。 another way to test your application is 测试应用程序的另一种方法是

  1. Create a Console Application Project. 创建一个控制台应用程序项目。
  2. Copy service URL from the browser and then right click on project and select add service reference and then paste the URL you copied. 从浏览器复制服务URL,然后右键单击项目并选择添加服务引用,然后粘贴复制的URL。
  3. Then add your code as below. 然后,如下所示添加您的代码。 in your program.cs class 在您的program.cs类中

     ICalculatorClient calcClient = new CalculatorClient()); int value1 = 100; int value2 = 15; double result = calcClient.Addition(value1, value2); Console.WriteLine("Addition({0},{1}) = {2}", value1, value2, result); 

Note : you can find more information regarding this topic in msdn . 注意:您可以在msdn中找到有关此主题的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM