[edit=gfoidl] Thema umbenannt. Ursprünglich: Fragen zu Webservices [/edit]
Hallo allerseits,
ich habe ein paar Fragen zu Webservices.
Gehen wir davon aus, ich habe folgende Umgebung:
[highlight=c#]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace MyService
{
[ServiceContract]
public interface ICustomService
{
[OperationContract]
CustomType[] getCustomType();
}
}
namespace MyService
{
public class CustomService : ICustomService
{
private CustomType[] ct;
public CustomType[] getCustomType(){
if (ct.Length>100)
throw new Excaption("100 überschritten");
else
return ct;
}
}[/highlight]
[highlight=c#]namespace MyHost
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("***** MyService Based WCF Host *****");
using (ServiceHost serviceHost = new
ServiceHost(typeof(CustomService)))
{
serviceHost.Open();
Console.WriteLine("The service is read.");
Console.WriteLine("Press the Enter key to terminate
Service.");
Console.ReadLine();
}
}
}
}[/highlight]
[highlight=xml]<!--Host App.config-->
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MyService.CustomService"
behaviorConfiguration="MyServiceMEXBehavior" >
<endpoint address=""
binding="basicHttpBinding"
contract="MyService.ICustomService"/>
<!--Enable the MEX endpoint-->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<!--Need to add this so MEX knows the adress of our service-->
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/MyService"/>
</baseAddresses>
</host>
</service>
</services>
<!--A behavior definition for MEX-->
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceMEXBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>[/highlight]
[highlight=c#]namespace myType
{
public class CustomType
{
public int x { get; private set; }
public CustomType(int X)
{
CustomType.x=X;
}
}
}[/highlight]
[highlight=c#]// und einem einfachen Client der nur eine ServiceReference auf den Host hat und dem der CustomType bekannt ist.
Ansonsten ist dort aber nichts verändert.[/highlight]
Frage 1:
Was muss ich hier ändern, um meinen CustomType über den Webservice an einen Client übertragen zu können?
Frage 2:
Was muss ich machen, um die Excaption in getCustomType an den Client
weiterleiten zu können?
evtl. kommen noch Fragen dazu![Blinzeln](https://entwickler-forum.de/core/images/smilies/wink.png)
Aber könnt ihr mir vorerst dabei helfen?
MfG,
Tobias
Hallo allerseits,
ich habe ein paar Fragen zu Webservices.
Gehen wir davon aus, ich habe folgende Umgebung:
[highlight=c#]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
namespace MyService
{
[ServiceContract]
public interface ICustomService
{
[OperationContract]
CustomType[] getCustomType();
}
}
namespace MyService
{
public class CustomService : ICustomService
{
private CustomType[] ct;
public CustomType[] getCustomType(){
if (ct.Length>100)
throw new Excaption("100 überschritten");
else
return ct;
}
}[/highlight]
[highlight=c#]namespace MyHost
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("***** MyService Based WCF Host *****");
using (ServiceHost serviceHost = new
ServiceHost(typeof(CustomService)))
{
serviceHost.Open();
Console.WriteLine("The service is read.");
Console.WriteLine("Press the Enter key to terminate
Service.");
Console.ReadLine();
}
}
}
}[/highlight]
[highlight=xml]<!--Host App.config-->
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MyService.CustomService"
behaviorConfiguration="MyServiceMEXBehavior" >
<endpoint address=""
binding="basicHttpBinding"
contract="MyService.ICustomService"/>
<!--Enable the MEX endpoint-->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<!--Need to add this so MEX knows the adress of our service-->
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/MyService"/>
</baseAddresses>
</host>
</service>
</services>
<!--A behavior definition for MEX-->
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceMEXBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>[/highlight]
[highlight=c#]namespace myType
{
public class CustomType
{
public int x { get; private set; }
public CustomType(int X)
{
CustomType.x=X;
}
}
}[/highlight]
[highlight=c#]// und einem einfachen Client der nur eine ServiceReference auf den Host hat und dem der CustomType bekannt ist.
Ansonsten ist dort aber nichts verändert.[/highlight]
Frage 1:
Was muss ich hier ändern, um meinen CustomType über den Webservice an einen Client übertragen zu können?
Frage 2:
Was muss ich machen, um die Excaption in getCustomType an den Client
weiterleiten zu können?
evtl. kommen noch Fragen dazu
![Blinzeln](https://entwickler-forum.de/core/images/smilies/wink.png)
Aber könnt ihr mir vorerst dabei helfen?
MfG,
Tobias
Comment