请using (ServiceHost host = new ServiceHost(typeof(HelloService.HelloService)))在下面的代码中帮助获得例外
例外:只有绝对URI可用作基址
class Program
{
static void Main()
{
using (ServiceHost host = new ServiceHost(typeof(HelloService.HelloService)))
{
host.Open();
Console.WriteLine("Service Started");
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
public class HelloService : IHelloService
{
public string GetMessage(string Name)
{
return "Hello" + Name;
}
}
Run Code Online (Sandbox Code Playgroud)
[ServiceContract]
public interface IHelloService
{
[OperationContract]
string GetMessage(string Name);
}
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="HelloService.HelloService" behaviorConfiguration="mexBehaviour">
<endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService">
</endpoint>
<endpoint address="HelloService" binding="netTcpBinding" contract="HelloService.IHelloService"> …Run Code Online (Sandbox Code Playgroud) 任何人都可以告诉我,我没有使用系统名称空间,但字符串可用作字符串hello ="Hello"; 并且不会抛出任何编译时错误
但是,如果我写大写字符串,它就不可用.
sealed class SealedClass
{
public void PrintSealed()
{
string hello = "Hello";
}
}
Run Code Online (Sandbox Code Playgroud) 为什么我们对以下情况有不同的输出:
object obj = "Int32";
string str1 = "Int32";
string str2 = typeof(int).Name;
Console.WriteLine(obj == str1); // true
Console.WriteLine(str1 == str2); // true
Console.WriteLine(obj == str2); // false !?
Run Code Online (Sandbox Code Playgroud) 我得到参数计数不匹配异常:
获取未处理的异常:System.Reflection.TargetParameterCountException:参数计数不匹配.
码:
class Program
{
public static void Main()
{
ArrayList CustomerList = new ArrayList();
CustomerList.Add("Robinson");
CustomerList.Add("Pattison");
CustomerList.Add("Todd");
object[] obj = (object[])CustomerList.ToArray(typeof(object));
Assembly executingAssembly = Assembly.GetExecutingAssembly();
Type customerType = executingAssembly.GetType("LateBinding.Customer");
object customerInstance = Activator.CreateInstance(customerType);
MethodInfo method = customerType.GetMethod("printCustomerDetails");
string customerObject = (string)method.Invoke(customerInstance, obj);
Console.WriteLine("Value is : {0}", customerObject);
}
}
public class Customer
{
public string printCustomerDetails(object[] parameters)
{
string CustomerName = "";
foreach (object customer in parameters)
{
CustomerName = CustomerName + " " + customer;
}
return …Run Code Online (Sandbox Code Playgroud)