powered by simpleCommunicator - 2.0.59     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / WCF, Web Services, Remoting [игнор отключен] [закрыт для гостей] / Новичек WCF
11 сообщений из 11, страница 1 из 1
Новичек WCF
    #36560029
~PJ
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Коллеги
я новичек в использовании сервисов потому вопрос может быть очень примитивным ;-)
прошу не пинать

(может я не правильно понимаю) , но сервис виден для всех , кто заходит ну скажем так svcutil.exe http://192.168.1.3/?wsdl
и злоумышленник получает описание классов. Как запретить получать описание , подскажите пожалуйста.
Планируется написание приложения с аутентификацией через приложение .

Спасибо
...
Рейтинг: 0 / 0
Новичек WCF
    #36560037
Фотография bured
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
...
Рейтинг: 0 / 0
Новичек WCF
    #36564002
~PJ
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Спасибо
...
Рейтинг: 0 / 0
Новичек WCF
    #36564043
~PJ
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
еще один вопрос , почему то не получается обьявить DataContract и [DataMember]

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Collections;
using System.Configuration;
using System.Data;

namespace Host
{
	class Program
	{
  
		static void Main(string[] args)
		{
			// We did not separate contract from implementation.
			// Therefor service and contract are the same in this example.
			Type serviceType = typeof(Service);
			 
			ServiceHost host = new ServiceHost(serviceType, new Uri[] { new Uri("http://192.168.1.3/Service")} );
          			
			// Add behavior for our MEX endpoint   
			ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();   
			behavior.HttpGetEnabled = true;   
			host.Description.Behaviors.Add(behavior);   
			
			// Create basicHttpBinding endpoint at http://localhost: 8080 /Service/   
			host.AddServiceEndpoint(serviceType, new BasicHttpBinding(), "Service");   
			// Add MEX endpoint at http://localhost: 8080 /MEX/
			host.AddServiceEndpoint(typeof(IMetadataExchange), new BasicHttpBinding(), "MEX");   
			
			host.Open();

			Console.WriteLine("Service is ready, press any key to terminate.");  
			Console.ReadKey();
            host.Close();
		}
	}
    
    [DataContract]
    public class User
    {
        private int userid;
        [DataMember] 
         public int userId {
                             get { return userid;}
                                   set { userid =value;}
                                  }

    }

	[ServiceContract]
	class Service
	{
        public string err;
                
        private int activation;
        private string ConnectionString = "Data Source=....";
              
	    [OperationContract]
        bool IsLogin(string login,string pass)
        {
            bool r = false;
           
            SqlConnection connect = new SqlConnection(ConnectionString);
            SqlDataReader reader = null;
            SqlCommand command = new SqlCommand("dbo.mdUsers_GetByLoginPass", connect);
            command.CommandType = CommandType.StoredProcedure;
            try
            {
                command.Parameters.Add("@Nickname", SqlDbType.VarChar,  50 ).Value = login;
                command.Parameters.Add("@password", SqlDbType.NChar,  32 ).Value = pass;

                command.Connection.Open();
                reader = command.ExecuteReader();
                if (reader.Read())
                {
                    User.userid = (int)reader["userID"]; ;
                    activation = (int)reader["Activation"];
                    if (activation== 1 ) r = true;
                }
                //err = nickName + "," + password+","+Convert.ToString(userId);
            }
            catch (SqlException ex)
            {
                err = ex.ToString();
                r = false;
            }
            finally
            {
                reader.Close();
                command.Connection.Close();
            }


            return r;
        } 


студия дает сообщение на строки
[DataContract] public class User
error CS0246: The type or namespace name 'DataMember' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DataMemberAttribute' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DataContract' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DataContractAttribute' could not be found (are you missing a using directive or an assembly reference?)


вот описание..
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
using System;
using System.Collections.Generic;
using System.Data;
using System.Runtime.Serialization;

namespace Client.localhost
{

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialiation", "4.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name = "User")]
    public partial class User //: Object, System.Runtime.Serialization.IExtensibleDataObject
    {

        private int userIdField;

        [System.Runtime.Serialization.DataMemberAttribute()]
        public int userId
        {
            get 
            {
                return this.userIdField;
            }
            set 
            {
                this.userIdField = value;
            }
        }
    }

    //---------------------------------------------------------------------------------------------------
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName="Client.localhost.Service")]
    public interface Service
    {
        
  
        [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/Service/IsLogin", ReplyAction = "http://tempuri.org/Service/IsLoginResponse")]
        bool IsLogin(string login,string pass);

    

подскажите пожалуйста !
...
Рейтинг: 0 / 0
Новичек WCF
    #36564088
AlexeiK
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
~PJ,

добави ссылку в проект(reference) на сборку которую используешь в using.
...
Рейтинг: 0 / 0
Новичек WCF
    #36564096
~PJ
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
если Вы про эти (ниже) , то они добавлены .

using System.Runtime.Serialization;
using System.ServiceModel;
...
Рейтинг: 0 / 0
Новичек WCF
    #36564107
~PJ
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Сори действительно не добавлены..
...
Рейтинг: 0 / 0
Новичек WCF
    #36565048
~PJ
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
пытаюсь получить класс User и параметр userId на клиенте

в сервисе делаю так
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
 [DataContract]
    public class User
    {
        private int userid;
        [DataMember] 
         public int userId {
                             get { return userid;}
                                   set { userid =value;}
                                  }

    }


    [OperationContract]
        bool IsLogin(string login,string pass)
        {
            User u=new User();
           .....
                if (reader.Read())
                {
                    User.userid = (int)reader["userID"]; 

описание
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
 [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialiation", "4.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name = "User")]
    public partial class User //: Object, System.Runtime.Serialization.IExtensibleDataObject
    {
        private int userid;
        [System.Runtime.Serialization.DataMemberAttribute()]
        public int userId
        {
            get 
            {
                return this.userid;
            }
            set 
            {
                this.userid = value;
            }
        }
    }

подскажите пожалуйста , что делаю не так . И как правильно, чтоб на клиенте получить userId.
...
Рейтинг: 0 / 0
Новичек WCF
    #36565058
~PJ
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
в приведенном коде читать
вместо
User.userid = (int)reader["userID"];
вот так
u.userid = (int)reader["userID"];
...
Рейтинг: 0 / 0
Новичек WCF
    #36566482
~PJ
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
что то очень сложное спрашиваю ? ;-(
...
Рейтинг: 0 / 0
Новичек WCF
    #36566568
Фотография buser
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: plaintext
[OperationContract] User TryToLogin(string login,string pass)
сделайте так и мозг не парьте... и еще из ваших слов и примеров не ясно что и как вы делаете...
...
Рейтинг: 0 / 0
11 сообщений из 11, страница 1 из 1
Форумы / WCF, Web Services, Remoting [игнор отключен] [закрыт для гостей] / Новичек WCF
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]